Give me a clue about what is wrong here


#1

Hi mtf, if you can give me a clue about what is wrong here, I will be really happy:
(students list is defined earlier after the dictionary definitions)

def get_class_average(students):
results=[]
for student in students:
av=get_average(student)
results.append(av)
return average(results)
print average(results)
print students
print get_letter_grade(average(results))

I get "Oops, try again. Did you remember to print the average of the class? It looks like "83.8666666667" wasn't printed." message.. whats weird is that during the former lesson the same code without the last two lines worked and I could passed to this lesson.. now why does it give this message I am totally lost:(

BTW I have another q as well : we define functions and without referring them they still work! In last lesson for instance shouldnt i explicitly use the function in the main body of the script.py (thats, out of the function def.s) to make it run? Why do those function work on their own without calling (or referring to) them?

Thank you in advance, the questions are too elementary for you, i know..


How's everybody doing?
#2

Sorry for the lack of indentations, neither copy-paste nor later placing spaces didnt work to get the code in indented format here..


#3

OK now it worked:) but i still have the second q in my mind.. is it because the interpreter works only to teach us and so we can pass through the lessons or is it really because the functions work without a call to them in the main body.. i am still confused..

lloyd = {
    "name": "Lloyd",
    "homework": [90.0, 97.0, 75.0, 92.0],
    "quizzes": [88.0, 40.0, 94.0],
    "tests": [75.0, 90.0]
}
alice = {
    "name": "Alice",
    "homework": [100.0, 92.0, 98.0, 100.0],
    "quizzes": [82.0, 83.0, 91.0],
    "tests": [89.0, 97.0]
}
tyler = {
    "name": "Tyler",
    "homework": [0.0, 87.0, 75.0, 22.0],
    "quizzes": [0.0, 75.0, 78.0],
    "tests": [100.0, 100.0]
}

# Add your function below!
students=[lloyd, alice, tyler]
def average(numbers):
    total=float(sum(numbers))
    total/=len(numbers)
    return total

def get_average(student):
    homework=0.1*average(student["homework"])
    quizzes=0.3*average(student["quizzes"])
    tests=0.6*average(student["tests"])
    return homework+quizzes+tests 
def get_letter_grade(score):
    if score>=90:
        return "A"
    elif score>=80:
        return "B"
    elif score>=70:
        return "C"
    elif score>=60:
        return "D"
    else:
        return "F"
    print get_letter_grade(get_average(lloyd))
def get_class_average(students):
    results=[]
    for student in students:
        av=get_average(student)
        results.append(av)
    return average(results)
print average(results)
print get_letter_grade(average(results))

#4
print get_class_average(students)

#5

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.