I can't figure out the error in my "def get_class_average" function


#1



The editor is giving me a 'Syntax error: invalid syntax' error for the following line:

def get_class_average(students):

Can someone tell me what the error is? thanks. Here's my code:

lloyd = {
    "name": "Lloyd",
    "homework": [90.0, 97.0, 75.0, 92.0],
    "quizzes": [88.0, 40.0, 94.0],
    "tests": [75.0, 90.0]
}
alice = {
    "name": "Alice",
    "homework": [100.0, 92.0, 98.0, 100.0],
    "quizzes": [82.0, 83.0, 91.0],
    "tests": [89.0, 97.0]
}
tyler = {
    "name": "Tyler",
    "homework": [0.0, 87.0, 75.0, 22.0],
    "quizzes": [0.0, 75.0, 78.0],
    "tests": [100.0, 100.0]
}
# Add your function below!

#calculates average as total divided by number of measurments
def average(numbers):
    total = sum(numbers)
    total = float(total)
    return total / len(numbers)
def get_average(student):
    homework = average(student["homework"]) * 0.1 
    quizzes = average(student["quizzes"]) * 0.3 
    tests = average(student["tests"]) * 0.6 
    return homework + quizzes + tests
def get_letter_grade(score):
    if score >= 90:
        return "A"
    elif score < 90 and score >= 80:
        return "B"
    elif score < 80 and score >= 70:
        return "C"
    elif score < 70 and score >= 60:
        return "D"
    else: 
        return "F"
# class average 
def get_class_average(students):
    results = []
    for student in students
        results.append(get_average(student))
        return average(results)


#2

a function ends the moment a return keyword is reached, this is currently happening in the first iteration of your loop. Change the indent of return so the whole for loop can run


#3

I did that but it still doesn't work. You can't see it in this paste (I don't know html editing), but the results and for lines are indented 1, results.append is indented 2, and return is indented 3. Do you have another thought? thanks again!

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

#4

if you want the return to happen after the for loop it should have the same indent level as the for loop, if the indention is more (more spaces/tab) it is nested inside the for loop


#5

that makes sense, but i'm still getting the same "syntax" error message for the for student in students line

File "python", line 46
for student in students
^
SyntaxError: invalid syntax

here's the whole code:

lloyd = {
    "name": "Lloyd",
    "homework": [90.0, 97.0, 75.0, 92.0],
    "quizzes": [88.0, 40.0, 94.0],
    "tests": [75.0, 90.0]
}
alice = {
    "name": "Alice",
    "homework": [100.0, 92.0, 98.0, 100.0],
    "quizzes": [82.0, 83.0, 91.0],
    "tests": [89.0, 97.0]
}
tyler = {
    "name": "Tyler",
    "homework": [0.0, 87.0, 75.0, 22.0],
    "quizzes": [0.0, 75.0, 78.0],
    "tests": [100.0, 100.0]
}

# Add your function below!
students = [lloyd, alice, tyler]
def average(numbers):
    total = sum(numbers)
    total = float(total)
    return total / len(numbers)
def get_average(student):
    homework = average(student["homework"]) * 0.1 
    quizzes = average(student["quizzes"]) * 0.3 
    tests = average(student["tests"]) * 0.6 
    return homework + quizzes + tests
def get_letter_grade(score):
    if score >= 90:
        return "A"
    elif score < 90 and score >= 80:
        return "B"
    elif score < 80 and score >= 70:
        return "C"
    elif score < 70 and score >= 60:
        return "D"
    else: 
        return "F"
    
# class average 
def get_class_average(students):
    results = []
    for student in students
        results.append(get_average(student))
    return average(results)

#6

and return is now indented the same as the for loop,


#7

for student in students # missing colon

see comment i code, now i will run it to see if it works

it seems to run fine now


#8

thank you, it works now!!! sorry to use up so much of your time, but the site is great for those of us new to coding.


#9

no problem.

yes, it is. Codecademy offers a great way to get in touch with coding, making the entry barrier really low


#12