Part of the Whole Debugging Problems


#1



I have been having a ton of trouble with this exercise (?) I would love for someone to take a look at it.

It gives me this error
Oops, try again. get_class_average([alice, lloyd]) returned 91.15 instead of 85.85 as expected


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]
}
def average(numbers):
    total = sum(numbers)
    total = float(total) 
    return total / len(numbers)
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.0:
        return "A"
    elif score >= 80.0:
        return "B"
    elif score >= 70.0:
        return "C"
    elif score >= 60.0:
        return "D"
    else:
        return "F"
get_letter_grade(get_average(lloyd))
def get_class_average(students):
    results = []
    for student in students:
        results.append(get_average(student))
        return average(results)


#2

Hello

Make sure that your return average(results) is indented correctly.
It must be in line with for above it.

Let me know if that helps.


#3

I'm not completely sure how that affects the program from what it told me, but that fixed it.


#4

Python uses indentations to code into blocks.

Whenever you create a block, a group of code that works together, you need whitespace(indentations) to tell python that the following lines are all part of the block.

Indentation is important because you can't write a loop or a function without it.
Ask yourself which lines of code relate to one another in the above lesson.


#5

If you feel that your topic was solved, do not forget to mark it as such. Other students might have the same question you had and this could help them.


#6

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