Sending a letter printing the wrong grade


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

def get_average(student):
homework = average(student["homework"])*0.1
quizzes = average(student["quizzes"])*0.3
tests = average(student["tests"])*0.6
return homework + quizzes + 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"
return "F"

print get_letter_grade(lloyd)

for some reason this print "A" even thought lloyd's grade should be a "B" why is it not running the functions i have written and why is it assigning the letter "A" to lloyd?


the get_letter_grade only converts the average grade of a student into a letter grade, so first you need to calculate lloyds average grade (using get_average())


could you please show me how that would be done? im having trouble understanding even though the lesson says its correct and lets me move on to the next lesson.

edit- i was under the impression that just writing "print get_letter_grade(lloyd)" would make it perform all necessary functions


no, you first need to calculate the average of lloyd (get_average(lloyd)), this value we need to supply for get_letter_grade


im really sorry but i still dont get it you're telling me to use the get_average function to get a value and then use it in the get_letter_grade function, i know that i have to write get_average(lloyd) but how to i then translate that into the get letter grade function? either way my main problem is if i clearly haven't done that yet why is the lesson allowing me to move on and telling me what ive done is correct if it clearly isnt


well, you can store the result of get_average(lloyd) in a variable and pass this as value into calling get_letter_grade, or pass get_average(lloyd) directly as value when calling get_letter_grade()

calling the get_letter_grade() is not part of the instructions, so its not validated


ive now added score = get_average(lloyd) above the get_letter_grade function and now its printing the correct grade, i actually feel like quite a dummy having missed that but thanks for explaining it. im intrigues tho what exactly is it doing when it prints "A" if i dont have a lloyds average set to score, it it just assigning a random number for the purpose of the lesson or am i missing something. again thanks for the help


good you figured out :slight_smile:

I don't know why the wrong letter grade was printing


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