"Sending A Letter"- codecademy says the code works, but my function returns the wrong answer


#1


https://www.codecademy.com/en/courses/python-beginner-en-qzsCL/1/3?curriculum_id=4f89dab3d788890003000096


Codecademy says my code here "works" (as in it sends me on to the next stage), but I'm not getting the correct answer from my function. When I run Lloyd's score through the interpreter with my code, it concludes "80.55" and makes his letter grade "F."

Can anyone help explain to me why this is happening? Is it that my get_average(Lloyd) function is working correctly, but the computer doesn't know how to read get_letter_grade because I only have "score" defined within get_average(Lloyd)? If so, how do I assign a variable to the result of my first function that the computer will recognize outside of the first function? (I tried score= "get_average(student)" but that gave me an error message.)

Any help is much appreciated!


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)
    average= total / len(numbers)
    return average
    
student= [lloyd, alice, tyler]
    
def get_average(student):
    homework= average(student["homework"])
    quizzes= average(student["quizzes"])
    tests= average(student["tests"])
    score= (homework * .1) + (quizzes * .3) + \
    (tests * .6)
    print score
    
def get_letter_grade(score):
    if score >= 90.0:
            return "A"
    elif score >= 80.0:
            return "B"
    elif score >= 70.0:
            return "C"
    elif score >= 60.0:
            return "D"
    elif score < 60.0:
            return "F"

print get_letter_grade(get_average(lloyd))


#2

To send a value back from a function use a return statement.


#3

Thank you! That helps :slight_smile:


#4

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