11. student becomes teacher. (Part of the whole)


#1

`def get_class_average(students):
results = []
for student in students:
average = get_average(student)
results.append(average)
print average(results)

error:
Traceback (most recent call last):
File "python", line 55, in
File "python", line 53, in get_class_average
TypeError: 'float' object is not callable


#2

In your code do you also have that first character `?


#3

no
it is just for representation that it is a code


#4

Can you paste your whole code? Place it between three backquote ` characters before and after your code


#5

One more thing, you want the function get_class_average(students) to return the average of results, not to print it.


#6

Pasted between three backticks fore and aft...

def get_class_average(students):
    results = []
    for student in students:
        average = get_average(student)
        results.append(average)
    print average(results)

Pasted and formatted with block sample tool </>

Traceback (most recent call last):
  File "python", line 55, in 
  File "python", line 53, in get_class_average
TypeError: 'float' object is not callable

#7

@mtf, one question. You, as the moderator, have an access to his original code or everyone can somehow reproduce how this code looks like?


#8

@dawidrz87 we can see his original post and take the code out of there and format it properly :slightly_smiling:


#9

In my example above, I copied straight off the screen and pasted it right into my post. Just adding the markdown above and below the code snapped it into the orginal code format, which is preserved, even when the screen output doesn't show that.


#10

So, this was marked as the solution, but it didn't solve anything. It's just the original code, but formatted properly. When I put this in, I get the same error as OP.


#11

Nevermind, I figured it out from another post. After the function, you have to make a list of the students' names, and then print the output of the get_class_average function with your list as the argument.


#12

which was the point. Unformatted Python code samples are not as straight forward to solve as they appear, since we are missing one vital component: scope. If the OP marked it solved, then they must have discovered their issue.