# Sending a letter. Didn't work, then randomly it did... In case you need it

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

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"])
sum=(homework*.10)+(quizzes*.30)+(tests*.60)
return sum
print sum

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

#2

Problem1.
mentioned by @mb13

problem 2.
get_average function takes a list not dictionary as argument.
by passing lloyd, you are passing dictionary in it and thus it throws an error.

hint**
Comment out that line of code , do reply if it worked or not.

#3

you appear to have a typo in your get_average(). try changing llyod to lloyd.

#4

fixed! thank you
Tho the error still exist in asker's code As I mentioned!

#5

Looks like the author made the same mistake.

#6

Sometimes Its useful to not mention all possible errors as it become spoon feeding and author will have nothing new to learn!

#7

I have some problem get letter grade don't work and I don't know why
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)
result = float(total)/len(numbers)
return result
def get_average(student):
homework = average(student["homework"])
quizzes = average(student["quizzes"])
tests = average(student["tests"])
score = 0.1*average(student["homework"])+0.3*average(student["quizzes"])+0.6*average(student["tests"])
return 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_average(lloyd)
print get_average(alice)
print get_average(tyler)

#8

By passing student's name you're passing dictionary to it but it needs a number(score).
Because the score can be calculated using `get_average()` function..

You have to pass`get_average(students name)` to `get_letter_average()` to get the grade,
I hope it helps!
.

#9

thank you very much, and I solve my problem.
def average(numbers):
total = sum(numbers)
result = float(total)/len(numbers)
return result
def get_average(student):
homework = average(student["homework"])
quizzes = average(student["quizzes"])
tests = average(student["tests"])
score = 0.1*average(student["homework"])+0.3*average(student["quizzes"])+0.6*average(student["tests"])
return 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_average(lloyd)
print get_average(alice)
print get_average(tyler)