8. Part of the whole


#1



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


get_class_average([alice]) returned 83.8666666667 instead of 91.15 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]
}

class_list = [lloyd, alice, tyler]

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

def get_average(student):
    
    homework = average(student["homework"])
    quizzes = average(student["quizzes"])
    tests = average(student["tests"])
    
    return homework * .1 + quizzes * .3 + tests * .6
    
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"
        
print get_letter_grade(get_average(lloyd))

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

#2

here:

for students in class_list:

you shouldn't loop over class_list, look:

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

print get_class_average([lloyd])
print get_class_average([lloyd, alice])
print get_class_average([lloyd, alice, tyler])

your function should work for all this function calls (so you can calculate the class average for a class of any size)

you might want to rename class_list to students, like instructed when creating the list, or you get in trouble at the next exercise


#3

im getting the same error ... could u plz post the correct code snippet


#4

Asking and posting answers is against the guidelines, if you need help, make a new topic (here, then new topic button), fill in the template so we have all the details needed to help you


#5

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