Students 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 =float(sum(numbers))
return 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

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):
result = []
for student in students:
result.append(get_average(student))
return average(result)

print get_letter_grade(get_class_average(students))

I am not sure what I have done wrong and was wondering if another pair of eyes could point it out to me. Thank you in advance!


#2

I apologize I may not have clarified, the error I get is:

Traceback (most recent call last):
File "python", line 52, in
NameError: name 'students' is not defined


#3

i think in this exercice there is a list named students contain lloyd , alice and tyler , No ??


#4

@azazaz is correct. The above line is referencing an object that is not defined in your code. Be sure to define it before this line.

students = [ lloyd, alice, tyler ]

print get_letter_grade ...

#5

@azazaz @mtf Does it matter where it is in the function? I added that right above the empty list "result" and I am still getting the same error. Also on this part of the lesson all it asks me to print the results of the above function that was done in the last section. Shouldn't it have told me something if the list wasn't there? Thanks again!!!


#6

The list object needs to be defined before it is referred. You can write it directly under the dictionaries if you like, then it is up with the other variable definitions.


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

students = [ lloyd, alice, tyler ]

Add your function below!

def average(numbers):
total =float(sum(numbers))
return 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

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):
result = []
for student in students:
result.append(get_average(student))
return average(result)

print get_class_average(students)

Thank you this worked! adding it right under the dictionaries and then changing up the last line a tad to return the number and not the letter grade. Thank you so much for your help!!!


#8

Uploading...

I was looking at it a little further and noticed that it does ask me to get the letter grade, but when I typ it it it gives me some error that says the indices are suppose to be integers not stings. Nothing important to the workI have passed just for the power of knowledge.