newbie question

C

christhecomic

Writing simple program asking a question with the answer being "yes"...how do I allow the correct answer if user types Yes, yes, or YES?

Thanks
 
C

Chris Angelico

Writing simple program asking a question with the answer being "yes"...how do I allow the correct answer if user types Yes, yes, or YES?

The thing you're looking for is case-folding, or possibly
lower-casing. You should be able to find what you want with that. :)

ChrisA
 
G

Gene Heskett

Writing simple program asking a question with the answer being
"yes"...how do I allow the correct answer if user types Yes, yes, or
YES?

Thanks

AND each character coming in from the keyboard with $DF before adding it to
the comparison buffer. Makes it all uppercase. Then compare it to the
uppercase YES.

Cheers, Gene
--
"There are four boxes to be used in defense of liberty:
soap, ballot, jury, and ammo. Please use in that order."
-Ed Howdershelt (Author)
My web page: <http://coyoteden.dyndns-free.com:85/gene> is up!
My views
<http://www.armchairpatriot.com/What Has America Become.shtml>
Although golf was originally restricted to wealthy, overweight Protestants,
today it's open to anybody who owns hideous clothing.
-- Dave Barry
A pen in the hand of this president is far more
dangerous than 200 million guns in the hands of
law-abiding citizens.
 
R

Rick Johnson

Writing simple program asking a question with the answer being
"yes"...how do I allow the correct answer if user types Yes,
yes, or YES?

Here is a clue.

py> 'e' == 'e'
True
py> 'E' == 'E'
True
 
S

Steven D'Aprano

Writing simple program asking a question with the answer being
"yes"...how do I allow the correct answer if user types Yes, yes, or
YES?

Take the user's input, strip off any whitespace from the beginning and
end, then fold the case to a consistent known form, e.g. lowercase.

# in Python 3.x, use input() rather than raw_input()
result = raw_input("Answer my question! ")
result = result.strip().lower()
if result == "yes":
...


For English words, like "yes", converting to lowercase will do the job.
But if you are using Python 3.3 or better, then I recommend you use
casefold() instead of lower() since that is smarter about converting case
when you have non-English characters.
 
I

Ian Kelly

AND each character coming in from the keyboard with $DF before adding it to
the comparison buffer. Makes it all uppercase. Then compare it to the
uppercase YES.

It's not working for me.
'\x9d\x91\x8f'
 
T

Tim Rowe

AND each character coming in from the keyboard with $DF before adding it to
the comparison buffer. Makes it all uppercase. Then compare it to the
uppercase YES.

Cheers, Gene

Hello, the 1970s called and want their hairstyles back! That is *terrible*
practice in a modern high-level language. Use the library functions. They
will take proper account of the character set being used (which you
shouldn't even have to know for a task like this, let alone make unsafe
assumptions about).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,773
Messages
2,569,594
Members
45,119
Latest member
IrmaNorcro
Top