Difficulty printing in a function


#1



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


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


#2

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:


#3

Got it, thank you!!

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


#4

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.


#5

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