# 8/9 why is there an error with get_class_average and get_average_student not defined?

#1

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

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

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(students):
results = {}
for student in students:
result = get_average_student
results.append(get_average(student))
return average(results)

#2

I'm pretty new to this, so take this with a grain of salt so to speak. but one thing that is important is posting it with your indentions, to do this, simply highlight your code, and press the "preformatted text" button ( looks like this </> ) . that being said here is the code that I found that works. so first, you created an empty dictionary instead of list (curly brackets instead of square). also creating the variable "result" doesn't seem to be needed. other than that, looks like you've got it
hope this helps in some way.

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

#3

Can somebody explain why it's "for s in students" instead of "for student in students"?

I don't understand why this works.

#4

This worked for me:

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

#5

As far as I understand it, that 's' or 'student' can be absolutely anything.

It's just saying:
Take an ITEM from some LIST

Neither ITEM or LIST has to be a sensible thing, really. You could just as easily write "for x in students"

In this particular case, "students" has to be "students" in the FOR statement, because that's how we defined our argument in the function "get_class_average"

If we wanted to, we could write:

``````def get_class average(stinky):
results = []
for silly in stinky:
etc....``````

That's at least how I think about it. Someone please feel free to correct me if I've written anything wrong or misleading.

#6

if im correct, i think he put an 's' instead of 'student' because earlier in the code it says
"def get_average(student):"

and in the if loop it will take the results of this 'student' and put it in the loop

#7

Dude you're a lifesaver

#8

thanks man you are epic