December 21st, 2012, 03:09 PM
Trouble using the sum function..
This is my code:
x = [1,2,3,4,5,6,7,8,9]
total = sum(x)
This is my error report:
Traceback (most recent call last):
File "python", line 3, in <module>
TypeError: 'int' object is not callable
I want to simply take the sum of the items in my list named x by using the sum function. What am I doing wrong and a correct way to do this would be appreciated.
December 21st, 2012, 03:22 PM
It's strange that it doesn't work for you. There's nothing wrong with your code. I don't think the sum() function is limited to any one version, but I suppose something could be off - so which version of Python are you using?
>>> x = [1,2,3,4,5,6,7,8,9]
>>> total = sum(x)
>>> print total
December 21st, 2012, 03:28 PM
Forgive and correct me if my vocabulary is incorrect.
I am using the compiler on a website called codecademy.com
Maybe the problem is on their end?
If you want to check it out, here is the majority of the url.. i'm not allowed to post whole ones
December 21st, 2012, 03:32 PM
Actually, there are no problems now. I didn't change anything either. Weird. Thanks for your time.
December 21st, 2012, 03:33 PM
No problem. Glad things worked out.
Good luck with Python