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 January 1st, 2013, 11:41 PM
sijones sijones is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 3 sijones User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 50 m 57 sec
Reputation 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.

Reply With Quote
  #2  
Old January 1st, 2013, 11:44 PM
sijones sijones is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 3 sijones User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 50 m 57 sec
Reputation Power: 0
..

Reply With Quote
  #3  
Old January 1st, 2013, 11:59 PM
sijones sijones is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 3 sijones User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 50 m 57 sec
Reputation Power: 0
..

Reply With Quote
  #4  
Old January 2nd, 2013, 01:15 AM
Nyktos Nyktos is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 75 Nyktos User rank is Corporal (100 - 500 Reputation Level)Nyktos User rank is Corporal (100 - 500 Reputation Level)Nyktos User rank is Corporal (100 - 500 Reputation Level)Nyktos User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 1 Day 2 h 56 m 44 sec
Reputation Power: 2
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!

Reply With Quote
  #5  
Old January 2nd, 2013, 08:25 AM
b49P23TIvg's Avatar
b49P23TIvg b49P23TIvg is offline
Contributing User
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Aug 2011
Posts: 3,357 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 9 h 6 m 43 sec
Reputation Power: 383
print not Print nor PRINT
__________________
[code]Code tags[/code] are essential for python code!

Reply With Quote
  #6  
Old January 14th, 2013, 04:22 PM
merdox merdox is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 1 merdox User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 17 m
Reputation 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.")

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > Simple Input and Conditions problem

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