Sending a letter


#1

https://www.codecademy.com/courses/learn-python/lessons/student-becomes-the-teacher/exercises/sending-a-letter?action=resume_content_item

Hi,

My following code passed and printed an average of 80.55 and an “F” (when is should be a “B”). Why is that?

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

def get_average(student):
homework= 0.1average(student[“homework”])
quizzes= 0.3
average(student[“quizzes”])
tests= 0.6*average(student[“tests”])

print homework+quizzes+tests

def get_letter_grade(score):
if score >= 90.0:
return “A”
elif score >= 80.0 and score < 90.0:
return “B”
elif score >=70.0 and score < 80.0:
return “C”
elif score >=60.0 and score < 70.0:
return “D”
else:
return “F”
print get_letter_grade(get_average(lloyd))


#2

get_average(lloyd) returns None, so you pass None to get_letter_grade function call, which will give F (given None isn’t greater then any of the integer values)


#3

Why does it return None? How do I fix it so I can get it to print the appropriate letter grade?


#4

because None is the default returned value. If we want to return something else, use the return keyword

the return statement should have been added in the lesson you made the get_average function, maybe revisit that exercise?


#5

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