7. Sending a letter


#1



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


My code could work but the result of score was wrong (all students were "A").
Where lacked something please let me know.
Thanks.


80< score <90 should be "B"


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]
}

students=[lloyd,alice,tyler]

# Add your function below!
def average(numbers):
    total = sum(numbers)
    total = float(total)
    return float(total)/len(numbers)

def get_average(student):
    homework = average(student["homework"])
    quizzes = average(student["quizzes"]) 
    tests = average(student["tests"]) 
    #print sum((0.1*homework,0.3*quizzes,0.6*tests))
    return sum((0.1*homework,0.3*quizzes,0.6*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"
    else :
        return "F"
        
        
for key in students:
    print key["name"]
    print "average:" ;print get_average(key)
    print "score:"
    print get_letter_grade(key)

The result showed

Lloyd
average:
80.55
score:
A
Alice
average:
91.15
score:
A
Tyler
average:
79.9
score:
A
None


#2

The problem is that when you call get_letter_grade(), the argument that you pass is not the result of the get_average() function.

It supposed to be like this:

print get_letter_grade(get_average(key))

#3

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