Some help in ex.8-Part of a Whole pls


#1

Im stuck at Part of a Whole

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

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

def get_average(student):
    homework = average(student["homework"])
    quizzes = average(student["quizzes"])
    tests = average(student["tests"])
    homework_weighted = homework * 0.1
    quizzes_weighted = quizzes * 0.3
    tests_weighted = tests * 0.6
    result = homework_weighted + quizzes_weighted + tests_weighted
    return result
    
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(get_average(lloyd))
students = [lloyd, alice, tyler]
def get_class_average(students):
    results = []
    for student in students:
        adl = get_average(student)
        results.append(adl)
        return average(results)


#2

To produce 88.85 from [alice, lloyd] some particular steps should be executed - add prints to find out what steps it is carrying out and compare to what it should be doing. You may want to do it manually first for reference


#3

I've done it but nothing seems to be going wrong, I've calculated it by myself and the results seems right


#4

Which one seems right? (I didn't even type the right number in previous message) but 85.85 or whatever it says is right (I trust this particular submission test)

So if you're getting the same result as your code, then you're miscalculating it. I don't think you would get the same result though, because your code doesn't behave quite as it should - again, adding prints lets you see what it does as it goes


#5

I actually went back to the previous lesson and practiced with the for loops and managed to get it, thanks!!!


#6

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