Difficulty printing in a function



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

I expected to see "total" (quotes added) to print after submitting the code.

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

def grades_sum(scores):
    total = 0
    for n in scores:
        total = total + n
    return total
    print total


You only need to return total. They just want you to return, and they want you to call the function and print what happens when you call the function. Basically, that just means writing

print grades_sum(grades)

because you are printing the result of passing grades to grades_sum. :slight_smile:


Got it, thank you!!

This is to meet the 20 character requirement to send a mail back to say thank you [:blush:]


Side note: Anything after return is unreachable. That is why your function did not print the result. However, this is more something to keep in mind in the future as it has no bearing on the exercise.


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