8/9 Part of the Wole


#1

Here's my code. When I run it, I get an error "Oops, try again. get_class_average([alice]) should return a number". Please help, I have no idea what's up with this :frowning:

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):
    sum(numbers)
    total = sum(numbers)
    total = float(total)
    return total / len(numbers)
    
def get_average(student):
    homework = average(student["homework"])
    quizzes = average(student["quizzes"])
    tests = average(student["tests"])
    return homework * 0.1 + quizzes * 0.3 + tests * 0.6
    
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(lloyd)

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

#2

Hi instead just returning results you should put results inside average()


#3

Alright, thanks! Can you explain why? It works, but I feel like it's no use if I didn't learn to do it on my own :frowning:


#4

I just follow the instruction

4. Finally, return the result of calling average() with results.


#5

Ah, my bad, didn't read the instructions carefully enough to begin with.


#6

hi
what rong here?
pls

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):
total = 0
homework = 0.1 * average(student["homework"])
quizzes = 0.3 * average(student["quizzes"])
tests = 0.6 * average(student["tests"])
total = total + homework + quizzes + tests
return total

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"
get_letter_grade = get_average(lloyd)
print get_letter_grade

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


#7

@dacyx

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


#9

my mistake...not work!
dont know what is rong in my lines

and error is this:

Oops, try again. get_class_average([alice]) resulted in an error: global name 'average' is not defined


#10

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

for better view


#11

I am getting the same error


#12

Here's what I did and worked fine:

The students list should not be included in the get_class_average function

At the end, you just need do call get_class_average(students):

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