9/4 Sum printing


#1



Please, explain what did I do wrong.

https://www.codecademy.com/courses/python-intermediate-en-7mgOa/1/1?curriculum_id=4f89dab3d788890003000096#


I got:
Oops, try again. Make sure to print the result of the grades_sum() function.

I expect:
1045.5 and cup of coffee, finally


def grades_sum(scores):
    '''(list) -> float
    >>>grades_sum([1, 2])
    3
    >>>grades_sum([100, 100, 90, 40, 80, 100, 85, 70, 90, 65, 90, 85, 50.5])
    1045.5
    >>>grades_sum([34, 62, 44])
    140
    '''
    total = 0
    
    for grade in scores:
        total += grade

    return total
    print(grades_sum(scores))


#2

From the code you've posted, it looks like you have indented that line with the function call. This means that you have your function call inside your function instead of after it.

Do you see the problem now?


#3

Oh God,

It wanted me to rename "grades" above the function to "scores"))) Now it works, thank you. Btw, what to you think, - maybe it make sense to use only 'grades' or only 'scores' in the task description (of course if ca did not mix them especially to make the task not so easy))))

scores = [100, 100, 90, 40, 80, 100, 85, 70, 90, 65, 90, 85, 50.5]

def grades_sum(scores):
'''(list) -> int

grades_sum([1, 2])
3
grades_sum([100, 100, 90, 40, 80, 100, 85, 70, 90, 65, 90, 85, 50.5])
1045.5
grades_sum([34, 62, 44])
140
'''
total = 0

for grade in scores:
    total += grade

return total

print(grades_sum(scores))


#4

To make the function generic and therefore reusable, in this case, you could use scores inside the function. Outside the function you would use grades. That way, later if you wanted to sum up another set of grades, for instance grade_class01, grades_class02, etc. then you wouldn't have to change the function itself, just the function call.


#5

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