Computing the Average


I can't understand why I keep getting an error on line 14 (invalid syntax)

Expecting for the code to work, printing the result of the grades_sum function and grades_average function with list grades. What am I doing wrong?

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

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

print grades_sum(grades)

def grades_average(grades):
    sum_grades = grades_sum(grades)
    avg_grades = sum_grades / (float(len(grades))
    return avg_grades

print grades_average(grades)


This exercise teach us something about using "Helper functions" (You can search and read about it)

also why the error?

avg_grades = sum_grades / (float(len(grades))

check this line of code.


Thank you! Missing a parenthesis! I was thrown off because it referred to the line below and I just kept staring at it like hoooooooooooooww? :slight_smile:


Yeah ,Its a good observation that whenever we get syntax error, look at line above that it (CC interpreter) points ,also same line. :slight_smile:


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