TypeError: 'float' object is not callable...but I didn't rename the function...the DQ platform did!

Screen Link:

My Code:

from numpy.random import randint, seed


What I expected to happen:
I expected 2 as an output

What actually happened:

TypeErrorTraceback (most recent call last)
<ipython-input-1-7ba9ec2494be> in <module>()
      1 from numpy.random import randint, seed
----> 3 mean([1,2,3])

TypeError: 'float' object is not callable

I tried the usual fix of deleting the variable mean (which was created on the previous screen, as per the instructions/answer-checking requirements) using del mean. But then I get:

NameErrorTraceback (most recent call last)
<ipython-input-1-616250aa3479> in <module>()
      1 from numpy.random import randint, seed
      2 del mean
----> 3 mean([1,2,3])

NameError: name 'mean' is not defined

Is there any way to fix this or is it “doomed” because it’s part of the expected answer on the previous screen and therefore silently runs in the background?

1 Like

I am not entirely sure what you are trying to do, but the error is as expected.

In the previous screen you refer to, we are asked to store the mean of the distribution into the variable called mean.

The mean of the distribution is a float value, and so mean is a variable of type float.

It’s not a function.

So, when you try to do -

The above throws an error because you are trying to call a float type variable as a function. That’s why the error message states -


You seem to be under the impression that there is a thing such as a built-in mean function. There isn’t.

Precisely the source of my blunder, thank you @Bruno!

I see now, after a quick Google, that it’s a function in the statistics package…I could have sworn there was a built-in mean() function tho!

Assumptions are my worst enemy :triumph: