8 Part of the whole


Part of the whole

Oops, try again. get_class_average([alice]) returned 83.8666666667 instead of 91.15 as expected

Hey guys, I can't seem to figure out why the alice average is off. Any help would be greatly appreciated, thanks!

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'
        return 'F'
print get_letter_grade(get_average(lloyd))   

def get_class_average(students):
    students = [lloyd, alice, tyler]
    results = []
    for student in students:
    return average(results)


Read your code and consider what it would do with the argument [alice]. If you still don't find it, then start adding print statements to find out what it does step by step and compare that output to what you know it should be doing.


I threw in a few print statements and it looks like everything is working fine until I get to class average. Before that point the average I get returned is 91.15, the same value asked. I've double checked my code several times now but am still not sure how to proceed.


Do you mean that you are testing the average function with alice as the argument?
If that returns 91.15, then what's the average of that? It's 91.15 / 1, which is 91.15
What numbers is your class average function using? Probably not those numbers. Which? Have it tell you:

getting average for: { ... }
total is now: ..

getting average for: { .. }
total is now: ..


dividing by: ..
final result is: ..

Your program is carrying out actions, they are very few actions so it's very reasonable to just observe them all and compare.


You should not write this line in the function. A function is supposed to work with any GIVEN argument and here you have defined/fixed the argument inside the function. If you remove it, it should work correctly.

To call this function, you should do like this:

print get_class_average([alice, lloyd])


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