8.Part of the Whole - Syntax error on a return


#1



https://www.codecademy.com/courses/python-beginner-en-qzsCL/resume?curriculum_id=4f89dab3d788890003000096


When i try to run the code I receive the following message:
File "python", line 45
return average(results)
^
SyntaxError: invalid syntax

it seems to be a Syntax error on the return line of the get_class_average function but i can't figure out what exactly i did wrong. i copied the function code below, line 45 is the return line


def get_class_average(students):
    results =[]
    for student in students:
       results.append(get_average(student) 
    return average(results)


#2

look at the line above the error message, pay special attention to your parentheses


#3

wow i can't believe i didn't notice i missed the second barcket

still, weird how the editor was pointing to the line below, is it because it didn't know where to end the line before the return?


#4

its surprising difficult to spot.

well, the thing with parentheses is that we can continue coding on the next line:

results.append(
    get_average(student)
)

is perfectly valid. So python assumes you wanted to continue coding on the next line, but then encountered syntax which didn't fit with what you where doing in the parentheses.

Don't stare yourself blind on a single line (tunnel vision), always focus on the bigger picture.


#5

thank you im used to ending sentences with semicolons like in C, so I have a hard time noticing when python decides the statement breaks


#6

but forgetting a semi-colon in C can have disastrous consequences as well, good luck finding it in a 1000+ lines of code :stuck_out_tongue:


#7

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