8. part of whole


8. Part of the Whole

Need help, got stuck on this exercise for a long tym!!!


I wonder if it is because now you are adding each student with the loop rather than just one student rewriting the value in the results list?


Your answer should be correct. Perhaps Codecademy fixed it, because my code resulted in the same number, and I'm shown the 'way to go!' message... Try again.


I had the same issue with the same results and in my case I had to move results = [] from outside of the function to inside of get_class_average function to reset the values.


I got that number too...
I'm not sure what the issue is, have been trying for 20 minutes now


Must've spent 20 minutes tweaking float() expressions and what not, thinking my arithmetic went wrong somewhere; just to find out that moving the results = [] to the inside of the function is what fixed it -_-


u suggest to move the return = [] from the outside to the inside of the function, but it is on the inside if you look at the screenshot given.

or do I miss something?


Hi there, I'm using a slight different set of code, but am getting an error

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

"Traceback (most recent call last):
File "python", line 49, in
NameError: name 'students' is not defined"

Not sure where to head next???


mine says "Oops, try again. get_class_average([alice, lloyd]) returned 91.15 instead of 85.85 as expected"...


I got it, you need to then create another variable and return that variable, that variable will = average(results)

def get_class_average(students):
results = []
for x in students:
avrg = get_average(x)
avrg_lst = results.append(avrg)
avg = average(results)
return avg


You appear to be missing a = sign in your list definition.
Try it like this:
students = [lloyd,alice,tyler]
Also note that I removed the " as it would be a list of strings in this case, whereas what you really need is a list of lists (so lloyd etc will be a variable instead that you defined earlier).
Also, you really must define students list outside of the function or you don't have anything to pass as parameters to the function.