[Tutor] [EXTERNAL]Re: sum() function
Alan Gauld
alan.gauld at yahoo.co.uk
Mon Nov 23 20:41:21 EST 2020
Always use Reply-All when responding to tutor list posts.
On 24/11/2020 01:06, Olsen, Avalow Y wrote:
> This is my complete code.
>
> numbers = [1,2,3,4,5,1,4,5]
> total = sum(numbers)
> print(total)
> ---------------------------------------------------------------------------
> TypeError Traceback (most recent call last)
> <ipython-input-24-3fb2ee1e5032> in <module>
> 1 numbers = [1,2,3,4,5,1,4,5]
> ----> 2 total = sum(numbers)
> 3 print(total)
>
> TypeError: 'int' object is not callable
OK, That should not error in any version of Python.
How are you running the code?
Is it in a file?
Or are you typing it straight into the interpreter in Jupyter?
If the latter I'd restart Jupyter and try again.
I suspect it may be holding onto an old assignment of sum.
Other things to try:
print(sum([1,2,3,4,5,1,4,5]))
help(sum)
If its a file try running it in the vanilla python interpreter
outside Jupyter.
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos
More information about the Tutor
mailing list