Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old December 21st, 2012, 02:09 PM
purdy purdy is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 3 purdy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 28 m 46 sec
Reputation Power: 0
Trouble using the sum function..

This is my code:
x = [1,2,3,4,5,6,7,8,9]

total = sum(x)
print total

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.

Reply With Quote
  #2  
Old December 21st, 2012, 02:22 PM
StevenJM StevenJM is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 12 StevenJM User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 51 m 27 sec
Reputation Power: 0
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?

Code:
>>> x = [1,2,3,4,5,6,7,8,9]
>>> total = sum(x)
>>> print total
45
>>> 

Reply With Quote
  #3  
Old December 21st, 2012, 02:28 PM
purdy purdy is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 3 purdy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 28 m 46 sec
Reputation Power: 0
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
codecademy.com/courses/python-beginner-en-qzsCL/1#!/exercises/0/scratchpad

Reply With Quote
  #4  
Old December 21st, 2012, 02:32 PM
purdy purdy is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 3 purdy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 28 m 46 sec
Reputation Power: 0
Actually, there are no problems now. I didn't change anything either. Weird. Thanks for your time.

Reply With Quote
  #5  
Old December 21st, 2012, 02:33 PM
StevenJM StevenJM is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 12 StevenJM User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 51 m 27 sec
Reputation Power: 0
No problem. Glad things worked out.

Good luck with Python

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > Trouble using the sum function..

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap