# Quick Question about the def functions used in 7.Sending a Letter

#1

``````Replace this line with your code.
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)
noob = total / len(numbers)
return noob

def get_average(student):
homework = average(student["homework"])
quizzes = average(student["quizzes"])
tests = average(student["tests"])
sumb = homework * 0.10 + quizzes * 0.30 + tests * 0.60
return sumb

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

Hi guys! New to programming and just had a question about the def functions in this exercise. (7. Sending a Letter).
The code does what it is supposed to do, but I'd like an explanation on how it works.

1. If I've not called average(numbers) and get_average(students), why are they still being used for my get_letter_grade function? (get_letter_grade(lloyd) the only one I called, during the print statement.)

2. How does get_letter_grade(lloyd) know to use the result from the get_average function? Can you explain whats going on step by step please?

Sorry if this is a noob question, but I'd like some help please.

#2

Letter grade is an artifact of the grading process. We cannot assign it to a computational value, only derive it from one. We need a weighted average to work from.

#5

I don't understand. Could you put it in simpler terms for me and explain the questions I asked. Sorry, but I haven't been able to find the answer.

Thanks

#6

@scriptslayer43157
Try to use following code

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

def get_average(student):
homework = average(student["homework"])
quizzes = average(student["quizzes"])
tests = average(student["tests"])
sumb = homework * 0.10 + quizzes * 0.30 + tests * 0.60
return sumb

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