# It doesn't work like it should, what's wrong with it?

#1

get_class_average([alice]) should return a number

``````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 = sum(numbers)
total = float(total)
total = total / len(numbers)

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

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

students = [lloyd, alice, tyler]

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

print get_class_average(students)

Been on this for too much time I think, I changed couple of things, but it still doesn't work like it should. It was returning a number before that current version, but not the right one for some reason, what's wrong with it?

#2

step 4 of the instructions:

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

you just return results, not the average of the results

#3

ah thank you, now it prints the correct numbers, but that new function for the exercise still seem to not work as it should since it still says it doesn't return a number, and to confirm that, the letter it return for class average is F, which doesn't need any particular score to trigger.

imma look for whats wrong again, but if you come here, i'd still apreciate the help; just in case.

#4

this is my output of your code:

``````B
A
C
80.55
91.15
79.9
83.8666666667
80.55
91.15
79.9
B``````

which seems fine? maybe you need to refresh the page, but everything is working as it should

#5

Idk, now I'm getting grade A as class average and still says alice should return a number...

#6

can i see an updated version of your code?

#7

``````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 = sum(numbers)
total = float(total)
total = total / len(numbers)

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

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

students = [lloyd, alice, tyler]

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

print get_class_average(students)

output is:

B
A
C
80.55
91.15
79.9
[80.55, 91.14999999999999, 79.9]
80.55
91.15
79.9
A
None

I also tried with
r = results.append(get_average(student))
return r

but that prints F as class grade

#8

you never applied the changes i suggested? this code:

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

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

which means you need to modify this line:

``    return results``

which you said you did and understood, but this doesn't seem to be the case

#9

sorry i am completely dumb, its working now, it was under my eyes since the beginning, but i overlooked it somehow, tysm mate

i have to say that its the first time since beginning that i really struggled, all these dictionnaries, lists and lists inside a key of a dictionnary, then properly attribute or call a value, etc... its confusing and need some training with

also i should be more careful when reading instructions next time, altho i think theres a problem with this exercise in particular, seeing all other people having issue with it

#10

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