Part of the Whole


#1

if i run submit code,
File "python", line 50
def get_class_average([lloyd, alice, tyler]):
^
SyntaxError: invalid syntax

this error cames, and that mean there is wrong with my def, why is wrong? it was worked fine before...


#2

can i see your full code? it can also be you forgot to close a parentheses on the line above


#3

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)
total = total / len(numbers)
return total

def get_average(student):
homework = average(student["homework"])
quizzes = average(student["quizzes"])
tests = average(student["tests"])
homework = 0.1 * homework
quizzes = 0.3 * quizzes
tests = 0.6 * tests
return homework + quizzes + tests

def get_letter_grade(score):
if score >= 90:
return "A"
elif score >= 80:
return "B"
elif score >= 70:
return "C"
elif score >= 60:
return "D"
else:
return "F"

print get_letter_grade(get_average(lloyd))

def get_class_average([lloyd, alice, tyler]):
results = []
for student in class:
restults.append(get_average(student))
return average(results)

Here you go


#4

a lists can't be a function parameter. See instructions what the function parameter should be


#5

restults.append(get_average(student)) Make sure your spelling is correct! Spelling is really picky, so even the smallest letter in a word can disrupt something here. An extra "t" has been added in "results".

Also, for this function:

def get_class_average([lloyd, alice, tyler]):
results = []
for student in class:
restults.append(get_average(student))
return average(results)

Instead of using their names, change it to (students):. See if that helps. Also, for your for student in class:, where is the argument coming from in class:? The argument should be coming from the argument in get_class_average() parameter.

Last thing. For what I just wrote in the paragraph above, the instructions list this:

For each student item in the class list, calculate get_average(student) and then call results.append() with that result.

That's pretty confusing with the word choice they used here. Instead of student, just use item.

Hope that helps!


#6

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