7. Sending a Letter


#1


Can someone help me on resolving the Issue.

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) / len(numbers)
    return total
    
def get_average(student):
    homework = average(student["homework"])
    quizzes = average(student["quizzes"])
    tests = average(student["tests"])
    weights = (homework * 0.1) + (quizzes * 0.3) + (tests * 0.6)
    return weights
    
def get_letter_grade(score):
    if score >= 90:
        print "A"
    elif score >= 80:
        print "B"
    elif score >= 70:
        print "C"
    elif score >= 60:
        print "D"
    else:
        print "F"

print get_letter_grade(get_average(lloyd))

What's worong with the above code?

The Error I'm getting is

Oops, try again. get_letter_grade(100) returned None instead of 'A' as expected.

B
None
None

Please help me in resolving the issue.


#2

in the error message:

Oops, try again. get_letter_grade(100) returned None instead of 'A'

is a very important clue: returned

You don't return the letter grades, you print them


#3

You need to use return instead of print.
@stetim94 got to it first, :slight_smile:
Be careful to read the instructions, because they are very clear. Especially on long things like this, you don't want to have errors because you spend time going through it.
The instructions said
If score is 90 or above: return "A"
Else if score is 80 or above: return "B"
Else if score is 70 or above: return "C"
Else if score is 60 or above: return "D"
Otherwise: return "F"

and basically gave you pseudocode that you had to turn into actual code.


#4

@kyleaw and @stetim94 Thanks for the quick turn around, issue got fixed. Thank you very much again!


#5