`Replace this line with your code.`

# Part of whole

**deanna5**#3

Help!!! I keep getting this message:

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

//Code

def get_class_average(students):

results = []

for student in students:

results.append(get_average(student))

return average(results)

**deanna5**#5

```
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 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"
homework = 0
quizzes = 0
tests = 0
# return (float (total) / length)
def get_average(student):
total_hw = 0
length_hw = 0
total_hw = sum(student["homework"])
length_hw = len(student["homework"])
homework = total_hw / float(length_hw)
total_qz = 0
length_qz = 0
total_qz = sum(student["quizzes"])
length_qz = len(student["quizzes"])
quizzes = total_qz / float(length_qz)
total_test = 0
length_test = 0
total_test = sum(student["tests"])
length_test = len(student["tests"])
tests = total_test / float(length_test)
return (.1 * homework + .3 * quizzes + .6 * tests)
# print get_letter_grade(get_average(lloyd))
def get_class_average(students):
results = []
for student in students:
results.append(get_average(student))
return average(results)
```

**deanna5**#7

loyd = {

"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 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"

homework = 0

quizzes = 0

tests = 0

# return (float (total) / length)

def get_average(student):

total_hw = 0

length_hw = 0

total_hw = sum(student["homework"])

length_hw = len(student["homework"])

homework = total_hw / float(length_hw)

total_qz = 0

length_qz = 0

total_qz = sum(student["quizzes"])

length_qz = len(student["quizzes"])

quizzes = total_qz / float(length_qz)

total_test = 0

length_test = 0

total_test = sum(student["tests"])

length_test = len(student["tests"])

tests = total_test / float(length_test)

return (.1 * homework + .3 * quizzes + .6 * tests)

# print get_letter_grade(get_average(lloyd))

def get_class_average(students):

results = []

for student in students:

results.append(get_average(student))

return average(results)

**stetim94**#8

your `average()`

function is still missing, i linked to the exercise, please build the function again

**deanna5**#9

Thank you! Now I see. I thought that I could use one of the built in functions// Input Math... I even tried //Input Numpy... but that was returning 91.1111119 and was not accepted! I will fix!

**deanna5**#10

NEW ERROR

// Oops, try again. get_class_average([alice, lloyd]) returned 91.15 instead of 85.85 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]

}

# Add your function below!

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"

homework = 0

quizzes = 0

tests = 0

# return (float (total) / length)

def get_average(student):

total_hw = 0

length_hw = 0

total_hw = sum(student["homework"])

length_hw = len(student["homework"])

homework = total_hw / float(length_hw)

total_qz = 0

length_qz = 0

total_qz = sum(student["quizzes"])

length_qz = len(student["quizzes"])

quizzes = total_qz / float(length_qz)

total_test = 0

length_test = 0

total_test = sum(student["tests"])

length_test = len(student["tests"])

tests = total_test / float(length_test)

return (.1 * homework + .3 * quizzes + .6 * tests)

# print get_letter_grade(get_average(lloyd))

def average(numbers):

total=sum(numbers)

total= float(total)/len(numbers)

return total

def get_class_average(students):

results = []

for student in students:

results.append(get_average(student))

return average(results)

**stetim94**#11

nearly there.

A function ends the moment a return keyword is reached, if a return keyword is reached in a loop, the loop breaks so the function can end

**system**#13

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