0
votes

I am writing a function that takes an input that calls two other functions. I've had no problem writing the two other functions but for some reason I'm getting an error message writing the third, having to do with the syntax.

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

and I get an error code: def get_class_average(students): ^ SyntaxError: invalid syntax

What am I missing? There doesn't seem to be anything wrong with the way I wrote def.

2
well your tabs are all messed (in this question)up try python -tt my_script.py which will check for mixed tabs and spaces - Joran Beasley
That was only here on stackoverflow, I forgot to check my tabs when pasting here. I fixed it here, but my question was answered. - Nathan Wall

2 Answers

3
votes

Check the line before you define your def and make sure your syntax is correct for ending the statement.

2
votes

Every line after the first needs a tab.

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