943,797 Members | Top Members by Rank

Ad:
  • Python Discussion Thread
  • Marked Solved
  • Views: 403
  • Python RSS
May 6th, 2009
0

Problem with simple if statement

Expand Post »
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?

Python Syntax (Toggle Plain Text)
  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"
Similar Threads
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
kiddo39 is offline Offline
50 posts
since Nov 2008
May 6th, 2009
0

Re: Problem with simple if statement

"YES" is not the same as "yes".

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

python Syntax (Toggle Plain Text)
  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.
Featured Poster
Reputation Points: 975
Solved Threads: 140
Posting Virtuoso
scru is offline Offline
1,624 posts
since Feb 2007
May 6th, 2009
0

Re: Problem with simple if statement

Thanks!
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
kiddo39 is offline Offline
50 posts
since Nov 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Python Forum Timeline: validation logic
Next Thread in Python Forum Timeline: How to locate a line in a text file





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC