Not understanding why this doesn't work?


#1



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


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


#2

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?


#3

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.


#4

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


#5

you forgot the bracket.

test = average(student["tests"]

should be

test = average(student["tests"])

#6

Sigh...I'm an idiot.

Thanks mate, I appreciate it.


#7

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:
results.append(get_average(student))
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:


#8

I just figured out my problem


#9

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


#10

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