Thread: Help!?

    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    3
    Rep 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
  2. #2
  3. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,696
    Rep Power
    480
    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 and Makefiles!
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    3
    Rep Power
    0
    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.
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    3
    Rep 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?
  8. #5
  9. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,696
    Rep Power
    480
    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)
    [code]Code tags[/code] are essential for python code and Makefiles!

IMN logo majestic logo threadwatch logo seochat tools logo