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

    Join Date
    Jan 2013
    Posts
    3
    Rep Power
    0

    Simple Input and Conditions problem


    I'm trying to do this


    age = input("Pleas enter your age")
    if age> 60:
    Print ("Wow you are quite old")
    else:Print ("are not that old")

    i get an error

    Traceback (most recent call last):
    File "/Users/shallahjones/Desktop/python test.py", line 2, in <module>
    if age> 60:
    TypeError: unorderable types: str() > int()
    >>>

    why is it not printing correctly. Im new to this.
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    3
    Rep Power
    0
    ..
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    3
    Rep Power
    0
    ..
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    114
    Rep Power
    3
    The behaviour of the input function was changed from Python 2 to Python 3. In Python 2, it would evaluate the input given to it; while in Python 3 it simply returns it as a string. If you want an int, you'll have to call int() (or eval(), but don't do that) on it, like so:

    Code:
    age = int(input("Please enter your age: "))
    if age > 60:
        print("Wow, you are quite old.")
    else:
        print("You are not that old.")
    In addition, please put your code in code tags in the future. Code tags will preserve indentation which is very important in Python.

    Comments on this post

    • Dietrich agrees
  8. #5
  9. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,891
    Rep Power
    481
    print not Print nor PRINT
    [code]Code tags[/code] are essential for python code and Makefiles!
  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    1
    Rep Power
    0
    try this:
    Code:
    age = int(input("Please enter your age:\n ")) # \n will put your input in new line
    if int(age) > 60: # you have to compare an integer with integer !
        print("Wow, you are quite old.")
    else:
        print("You are not that old.")

IMN logo majestic logo threadwatch logo seochat tools logo