# How Is Everybody Doing - works but doesnt pass

#1

Student Becomes the Teacher: How Is Everybody Doing ?( ex # 9)
My Code ...............
def average(numbers) :
total = float(sum(numbers))
total /= float(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'
def get_class_average( students ) :
results = []
for student in students :
results.append(get_average(student))
return average(results)

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]
}

................end of my code:

Interface tells me ...
Oops, try again. One of the following is missing or broken when we tried to use it: alice, lloyd, tyler, students, get_class_average, get_letter_grade
What happens...
The code runs, and I get B,C,A,B on lloyd,alice,tyler, and class respectively

I expected to pass this unit

``Replace this line with your code.``

#2

Hello,

You need to make sure you're calculating get_average(student) for each student in students and then outside of the for loop you'll append.

``````for student in students:
get_average(student)
results.append(get_average(student))``````

Also to test your function you should create a list of students as the question specifies:
students = [lloyd, alice, tyler]

Using the above method allows you to use a simpler/cleaner method:
print get_class_average(students)

That should do the trick

#3

Well, I tried this and (i) got the same error message, and (ii) the execution generated the wrong answer for get_class_average(). It should be 'B' for 83, - instead it comes up with 'C' . It comes up with 'C' because the last value assigned to 'student' is tyler, which in turn is because 'student' is out-of-scope. ( I'm a bit surprised the compilation didn't choke )
I've both used 'students' and obviated it - same error message, and same execution results

#4

My apologies to readers . I didn't follow protocol for pasting code into this site, so all my whitespace got clobbered.
I got beyond this problem by adding 'print get_class_average(students)' I still don't understand the error message, but that fixed it.

#5

It passes because it is looking for the list students to be defined. That fixed my error message._

#8

I solved this problem by adding this sentement
"students=[lloyd.alice,tyller]"

#9

Thanks for the tip! I encountered same issue, but by adding the definition of â€śstudentsâ€ť, it works.

#10

Thanks for that, I had the same problem. Code was working, but I couldnâ€™t pass. This solved it.

#11

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