# Oops, try again. get_class_average([alice]) should return a number

#1

Hi,

i am not sure what the error is here, i tried writing the code in multiple ways. here is 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]
}

def average(numbers):
total = float(sum(numbers))
result = total / len(numbers)
return result

def get_average(student):
homework = average(student["homework"])
quizzes = average(student["quizzes"])
tests = average(student["tests"])
total = (homework*.1) + (quizzes*.3)+(tests * .6)

score = int(score)

if score >= 90:
return "A"

elif score >= 80:
return "B"
elif score >= 70:
return "C"

elif score >= 60:
return "D"

else:
return "F"

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

here is the ERROR:

Oops, try again. get_class_average([alice]) should return a number

#2

you should return the average of result. Use your average function to calculate the average of results, step 4 of the instructions:

Finally, return the result of calling average() with results

#3

Thank you, yes i missed this for as many times as i had to rewrite and delete

i did add it and still gave me another error but was able to fix it. whats interesting not sure how this is any different from my code:

Code that worked:

def get_class_average(students=[lloyd, alice, tyler]):
results=[]
for student in students:
i=get_average(student)

results.append(i)
return average(results)

MyCode_That didn't work :_

students = [lloyd, alice, tyler]

def get_class_average(student):
results=[]

for student in students:

results.append(get_average(student))

return average(results)

can you see any difference??

#4

of your code that works:

def get_class_average(students=[lloyd, alice, tyler]):

this look like a bad idea.

as for you non-working code, the problem is here:

def get_class_average(student):

look at the instructions:

Define a function called get_class_average that has one argument students. You can expect students to be a list containing your three students

students, you have student. That is why your code is not working, because students is the list you want to loop over:

for student in students:

but your list is stored in student, so that won't work

#5

Thank you!

sorry about the noobness!

#6

you're welcome

no need to apologize, programming is difficult, mistakes are easily made.

#7

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