Error on Part of the Whole page


#1



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


The code is correct. I have verified it by hand calculation. Yet I get the error "Oops, try again. get_class_average([alice]) returned 83.8666666667 instead of 91.15 as expected "
Why is the page calling the function with a student "alice"? Since this is a class average, the get_class_average function should be called with the list "students" (as per the instruction this is the name of list with all 3 students). If the get_class_average function is called with the student list, it will work properly.

FYI...there seems to be an error in the instructions. it states "For each student item in the class list". I think name of the list cannot be 'class'


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 get_average(student):
    h_total=sum(student["homework"])
    homework=float(h_total)/len(student["homework"])
                   
    q_total=sum(student["quizzes"])
    quiz=float(q_total)/len(student["quizzes"])
            
    t_total=sum(student["tests"])
    test=float(t_total)/len(student["tests"])
             
    w_h=homework*0.1
    w_q=quiz*0.3
    w_t=test*0.6
    
    score=w_h+w_q+w_t
    
    return score

print get_average(lloyd)
print get_average(alice)
print get_average(tyler)

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"
        
def get_class_average(s):
    results=[]
    
    for c in students:
        get_average(c)
        results.append(get_average(c))
            
    avg_result=sum(results)/len(results)
    return avg_result
    
get_class_average(students)
print get_class_average(students)


#2

but a class may change in size, new students can join or students can leave

so your function should work a class of any size (any list supplied as argument at function call)

so you should really use your function parameter (given parameters receive the argument supplied at function call)


#3

OK. Since the instruction asked the list "students" to be created, my assumption was that the list will have the names of all the students (names of new students are added and leaving names are removed). So, I used 'students' for the FOR loop within the call average function. I just replaced that with 's'(function parameter) and it works! .Thanks.


#4

nope, students is just a logic name for the function parameter


#5

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