Part of a whole


#1



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


i got everything good except when i save and submit i get error
Oops, try again. get_class_average([alice, lloyd]) returned 80.55 instead of 85.85 as expected so i tried to add 5.3 but then i get error Oops, try again. get_class_average([alice]) returned 96.45 instead of 91.15 as expected but the when i tried to run programme locally with get_class_average([alice]) i get 91.15 with out 5.3 is that it means that value of alice is correct for me but not llyod but i am sure that i entered all details correctly as per can any one help me


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 get_average(student):
    homework = 0.1*average(student["homework"])
    quizzes = 0.3*average(student["quizzes"])
    tests = 0.6*average(student["tests"])
    return homework+quizzes+tests
    
    
# Add your function below!
def average(number):
   total = float(sum(number))
   length= len(number)
   return total/length
def get_letter_grade(score):
    if(score>=90):
        return "A"
    elif(score>=80 and score<=89):
        return "B"
    elif(score>=70 and score <= 79):
        return "C"
    elif(score>=60 and score <= 69):
        return "D"
    else:
        return "F"
def get_class_average(students):
    i=0
    for student in students:
        results = []
        results.append(get_average(student))
# this where i added 5.3 manually
    return (average(results))


#2

Hi @shahidkhan0211,

In the get_class_average function, you do not need this ...

    i=0

This should be placed prior to the loop, so that results is initialized only once ...

    results = []

Make sure you use the original data for all the students.


#3

A post was split to a new topic: Part of the Whole


#5

#6

#8

thanks :slight_smile::slight_smile::grin:


#9

No problem; enjoy the course. :smile:


#10