11.8 Part of the Whole - error >>global name 'result' is not defined<<


Hello, fellas.

I’ve encountered the following error in task titled Part of the Whole:

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

My code:

def get_class_average(students):
results =
for student in students:
return average(results)

Where did I go wrong? :wink: Seems like nobody else had this issue… I’ll appreciate any help.

Ps. I have no idea how to intend code in this editor. Tab doesn’t work.




Here you’re trying to use result to access the list function append but the problem is that result wasn’t declared so that’s what’s causing the error.
You’ve declared results and you’re using result.

Check the instructions if there’s anything related with the name of the variable, if not, choose the one you want.


Thanks for your response. :slight_smile: I understand what the bug report says. But I don’t know how to repair the broken code. Also, the instructions order me to use this “results.append()” piece of code. Have a look at the screenshot.


Hi there :slight_smile:

I will explain what they want of you :slight_smile: :

1-they want you to define a get_class_average()
2-Create results=
3- (Whenever you see “For each” in that context keep in mind you need a ‘for loop’)

for student (the variable name they wanted) in students(create a list called students containing students names) : (end with colon)

4- return (get_average(results))

(In 4 you call the function get_average)

The code is therefore as follows:


def get_class_average(students):
for student in students:

return average(results)

print get_class_average(studentsList)

I included a print statement to guide you in testing the code. Hope this helps ! :slight_smile: :slight_smile: