Problem with simple if statement

Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: Nov 2008
Posts: 43
Reputation: kiddo39 is an unknown quantity at this point 
Solved Threads: 0
kiddo39 kiddo39 is offline Offline
Light Poster

Problem with simple if statement

 
0
  #1
May 6th, 2009
I can't seem to figure out what's wrong with this simple code. I have a user input and if it matches prints out 'That's good', if not prints out 'Too bad' but how can I get the input to ignore being case sensitive?

  1. ans=raw_input("Are you feeling well today? ")
  2. if ans == "yes":
  3. print "That's good"
  4. else:
  5. print "Too bad"

I want it so if someone enters "YES" it will still print "That's good"
Reply With Quote Quick reply to this message  
Join Date: Feb 2007
Posts: 1,606
Reputation: scru has a spectacular aura about scru has a spectacular aura about 
Solved Threads: 130
Featured Poster
scru's Avatar
scru scru is offline Offline
Posting Virtuoso

Re: Problem with simple if statement

 
0
  #2
May 6th, 2009
"YES" is not the same as "yes".

To rectify, convert the input to lower case. Something like:

  1. ans=raw_input("Are you feeling well today? ")
  2. if ans.lower() == "yes":
  3. print "That's good"
  4. else:
  5. print "Too bad"
Last edited by scru; May 6th, 2009 at 11:56 am.
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 43
Reputation: kiddo39 is an unknown quantity at this point 
Solved Threads: 0
kiddo39 kiddo39 is offline Offline
Light Poster

Re: Problem with simple if statement

 
0
  #3
May 6th, 2009
Thanks!
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC