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 7th, 2012, 11:28 AM
mikejcbs mikejcbs is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 3 mikejcbs User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 37 m 48 sec
Reputation Power: 0
Help!?

I am trying to write a program that finds any multiples of four between 0-100.
I have gotten this,

x = 0
while x < 100:
x += 1
if x % 4 == 0:
print, (x) ("is a multiple of 4")


But, when it tries to print it give me the error,



Traceback (most recent call last):
File "C:\Users\Jacobs\Desktop\Python\Multiples.py", line 6, in <module>
print, (x) ("is a multiple of 4")
TypeError: 'int' object is not callable
>>>


Any suggestions would be greatly appreciated,

Michael

Reply With Quote
  #2  
Old December 7th, 2012, 12:13 PM
b49P23TIvg's Avatar
b49P23TIvg b49P23TIvg is offline
Contributing User
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Aug 2011
Posts: 3,376 b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 3 Days 12 h 21 m 42 sec
Reputation Power: 383
I suggest that in python
object(parens)
indicates to call a function.

The expression (x) results in an integer, and that's why you got the message. Integers aren't callable.

Integers are objects with methods, as you can see from
Code:
>>> 8     .    __add__(22)
30


Integers don't have a __call__ method.

People usually express addition with + operator. The __add__ method takes place in the darkness behind the curtain.

Code:
for x in range(100):
    if x % 4 == 0:
        print(x , "is a multiple of 4") # looks better in python3
__________________
[code]Code tags[/code] are essential for python code!

Reply With Quote
  #3  
Old December 7th, 2012, 12:16 PM
mikejcbs mikejcbs is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 3 mikejcbs User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 37 m 48 sec
Reputation Power: 0
Quote:
Originally Posted by b49P23TIvg
I suggest that in python
object(parens)
indicates to call a function.

The expression (x) results in an integer, and that's why you got the message. Integers aren't callable.

Integers are objects with methods, as you can see from
Code:
>>> 8     .    __add__(22)
30


Integers don't have a __call__ method.

People usually express addition with + operator. The __add__ method takes place in the darkness behind the curtain.

Code:
for x in range(100):
    if x % 4 == 0:
        print(x , "is a multiple of 4") # looks better in python3


Thank you so much for your help! I really appreciate it.

Reply With Quote
  #4  
Old December 7th, 2012, 12:26 PM
mikejcbs mikejcbs is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 3 mikejcbs User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 37 m 48 sec
Reputation Power: 0
Second question even if I set x to start at 1 it still includes 0 as a multiple any way to prevent this?

Reply With Quote
  #5  
Old December 7th, 2012, 12:33 PM
b49P23TIvg's Avatar
b49P23TIvg b49P23TIvg is offline
Contributing User
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Aug 2011
Posts: 3,376 b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 3 Days 12 h 21 m 42 sec
Reputation Power: 383
Oh, you incremented before you tested. Sure, there are ways around that. Self-help in python is fairly easy.

>>> help(range)

thus

for x in range(1,101):


Your while loop was fine. I chose to expand the knowledge base. I've done it again! String formatting.
Code:
x = 0
while x < 100:
    x += 1
    if x % 4 == 0:
        print('%d is a multiple of 4'%x)

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > Help!?

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