This always happens: "get_class_average([alice]) resulted in an error: global name 'average' is not defined"


#1

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]
}

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

results = []

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

Pls help >_<


#2

Hi @timopow ,

Because your code is not formatted, it is difficult for other users to read and debug it. After code is been pasted into the editing window for posting, you can format it by selecting it, and then by clicking the </> button above the editing area. This will enable us to see important details, such as the indentation and underscores.

You should have a function named average, but it is missing. Also note that the function that computes an average for a student should be called get_average, but you named it find_average instead. As you update your code, you'll need to make sure you revise the function calls, such as the following, to be consistent with your renaming of the functions:

results.append(find_average(student))

The above will need to be changed to:

results.append(get_average(student))

#3

@geomaticmashups Thanks SO much :smiley: