8# Part of the whole


#1

i get this error i don't know what is the problem with my code
Oops, try again. get_class_average([alice, lloyd]) returned 91.15 instead of 85.85 as expected

here is my code

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"]) * 0.1
    quizzes = average(student["quizzes"]) * 0.3
    tests = average(student["tests"]) * 0.6
    final = homework + quizzes + tests
    return final
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(students):
    results = []
    for student in students:
        get_average(student)
        results.append(get_average(student))
        return average(results)

#2

a function ends the moment a return keyword is reached, this is currently happening in the first iteration of your loop.

change the indent of return so the whole for loop can run


#3

Also note that there is the following extra statement in your get_class_average function that does not accomplish anything ...

get_average(student)

It does not affect the result, but it should be removed because it is unnecessary.


#4

i deleted the extra statement thanks for the tip and i still don't know how to solve this ?


#5

Hi @hamzasalhi ,

Please post the most recent version of your get_class_average function so that we can address any remaining problems.


#6

did you read my answer? what did you not understand about it?


#7

yes bro i did but i can't see which one you're talking about i think that all the returns are in place .


#8

here is my new code :

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"]) * 0.1
quizzes = average(student["quizzes"]) * 0.3
tests = average(student["tests"]) * 0.6
final = homework + quizzes + tests
return final
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(students):
results = []
for student in students:
results.append(get_average(student))
return average(results)


#9

here:

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

is the function in question in which the return is off


#10

what is the solution bro what should i do delete it / replace it...
what is the solution exactly ?


#11

you have to delete a bit of indention


#12

can you modify the code and paste it here the correct one ( just the last function) because i tried everything but nothing seems to work for me


#13

i did it bro sorry the solution was so easy i was stupid i didn't notice that the return was there i needed to delete just a space


#14

hi guys please help me with this section can any body copy correct of this code??


#15

seriously, like hamzasalhi said, the mistake is pretty obvious once you see it

asking for answers is not according to the guidelines, please make a new topic so we can help you :slight_smile:


#16