[Tutor] [EXTERNAL]Re: sum() function

Olsen, Avalow Y Yuanyuan.A.Olsen at HealthPartners.Com
Mon Nov 23 21:37:14 EST 2020


Thanks, Alan!
I was typing it straight into the interpreter in Jupyter.  I restarted Jupyter and tried again. The problem went away.
By the way, there was no a sum variable in the previous assignments. The sum function didn’t work in my program. I created this snippet of test code to test the sum function.  And you know the rest of the story.

Thanks everyone for the help! This is such a supportive and enthusiastic community. I am proud to be part of it!
Ava

-----Original Message-----
From: Alan Gauld [mailto:alan.gauld at yahoo.co.uk]
Sent: Monday, November 23, 2020 7:41 PM
To: Olsen, Avalow Y <Yuanyuan.A.Olsen at HealthPartners.Com>
Cc: tutor <tutor at python.org>
Subject: Re: [EXTERNAL]Re: [Tutor] sum() function

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


________________________________

This e-mail and any files transmitted with it are confidential and are intended solely for the use of the individual or entity to whom they are addressed. If you are not the intended recipient or the individual responsible for delivering the e-mail to the intended recipient, please be advised that you have received this e-mail in error and that any use, dissemination, forwarding, printing, or copying of this e-mail is strictly prohibited.

If you have received this communication in error, please return it to the sender immediately and delete the original message and any copy of it from your computer system. If you have any questions concerning this message, please contact the sender. Disclaimer R001.0


More information about the Tutor mailing list