Not understanding why this doesn't work?


In regards to "Just Weight and See", not really understanding what I'm done wrong. I've looked at examples that are similar and they all more or less do the same thing, yet I keep getting a syntax error. What gives?

Edit: This is the error message I keep getting:

File "python", line 31
homeworksum = homework * .10
SyntaxError: invalid syntax

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!
def average(numbers):
    total = sum(numbers)
    total = float(total)
    product = total / len(numbers)
    return product
def get_average(student):
    homework = average(student["homework"])
    quiz = average(student["quizzes"])
    test = average(student["tests"]
    homeworksum = homework * .10
    quizsum = quiz * .30
    testsum = test * 60
    overallsum = homeworksum + quizsum + testsum
    return overallsum


I'm guessing that there's an error message telling you the line number where python is no longer able to make sense out of your code? Have you been looking in that area?


It's stated to be a syntax error, but I can't find out what the issue is. I've updated my original post to include the error message.


It reports the error at the location where it can no longer make sense out of it. The mistake may be earlier.


you forgot the bracket.

test = average(student["tests"]

should be

test = average(student["tests"])


Sigh...I'm an idiot.

Thanks mate, I appreciate it.


Hej everybody I have a question for the exercice just after this one (it is asking to calculate the average for the full class so here is what I did :

Class = (lloyd, alice, tyler)
def get_class_average(student):
results = []
for student in Class:
return get_class_average(student)

the problem is that it tells me that I don't get the right value for get_class_average (alice) (I get the average of the class which is 88.33 but it expect the average of alice which is 91.5)
I guess that my code take into account the full class to make the average, how can I solve that? (I mean that from what I understood the function should be able to take whateever input and not only the list that i gave him)
thx :slight_smile:


I just figured out my problem


It was supposed to be like that instead
def get_class_average(students): #students instead of student
____results = []
____for student in students:
____return average(results)


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