8. part of whole


#1


8. Part of the Whole
#2

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


#6

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?


#7

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.


#8

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.


#9

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


#10

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


#11

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?


#12

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

def get_class_average(students):
results = []
students["lloyd","alice","tyler"]
for student in students:
results.append(get_average(student))
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???


#13

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


#14

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


#15

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.


#17