Weird printing error with L9


#1


so there's a weird error with the printing in "How's Everybody Doing?" and I don't understand


all it says is "Oops, try again. Did you remember to print the letter grade for the class's average?"


I expected this to print both of them but it printed one and gave me the error message as seen above.
as you can see below my code works for the class average but for some reason not for individual scores

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"])
    quizzes = average(student["quizzes"])
    tests = average(student["tests"])
    return 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'
print (get_letter_grade(lloyd))

def get_class_average(students):
    results = []
    for student in students:
        results.append(get_average(student))
    return average(results)
    
print get_class_average(students)

print get_letter_grade(score)

Replace this line with your code.


#2

here:

print get_letter_grade(score)

score is a undefined variable. You will need to calculate the class average, convert this class average to a letter grade using get_letter_grade


#3

you need to include the function you are calling in place of the score variable, I believe. so basically you need to use get_class_average(students) as the argument instead of score. Try/Use:
print get_letter_grade(get_class_average(students))


#6

@stetim94
how did you make that box outline for your print statement in your comment? I know you can format something with a backtick to make it grayed-out but how did you add the box/border?


#7

you can also use:
print get_average(lloyd)
print get_average(alice)
print get_average(tyler)
to get individual scores in a cleaner method/approach..


#8

To print the class average, I used:
print get_class_average([lloyd, alice, tyler])


#9

or set a global variable of students = [lloyd, alice, tyler] then use print get_class_average(students). That works too.


#10

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