Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #48964 > unrolled thread
| Started by | christhecomic@gmail.com |
|---|---|
| First post | 2013-06-22 19:39 -0700 |
| Last post | 2013-06-25 20:26 +0100 |
| Articles | 7 — 7 participants |
Back to article view | Back to comp.lang.python
newbie question christhecomic@gmail.com - 2013-06-22 19:39 -0700
Re: newbie question Rick Johnson <rantingrickjohnson@gmail.com> - 2013-06-22 19:50 -0700
Re: newbie question Chris Angelico <rosuav@gmail.com> - 2013-06-23 12:48 +1000
Re: newbie question Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-06-23 03:08 +0000
Re: newbie question Gene Heskett <gheskett@wdtv.com> - 2013-06-22 22:49 -0400
Re: newbie question Ian Kelly <ian.g.kelly@gmail.com> - 2013-06-25 13:05 -0600
Re: newbie question Tim Rowe <digitig@gmail.com> - 2013-06-25 20:26 +0100
| From | christhecomic@gmail.com |
|---|---|
| Date | 2013-06-22 19:39 -0700 |
| Subject | newbie question |
| Message-ID | <195f7100-c4bf-414d-a92f-5b8a70d896f7@googlegroups.com> |
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
[toc] | [next] | [standalone]
| From | Rick Johnson <rantingrickjohnson@gmail.com> |
|---|---|
| Date | 2013-06-22 19:50 -0700 |
| Message-ID | <a249b957-1370-40dd-9a73-8a48dd2d32b2@googlegroups.com> |
| In reply to | #48964 |
On Saturday, June 22, 2013 9:39:30 PM UTC-5, christ...@gmail.com wrote: > 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
[toc] | [prev] | [next] | [standalone]
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Date | 2013-06-23 12:48 +1000 |
| Message-ID | <mailman.3721.1371955720.3114.python-list@python.org> |
| In reply to | #48964 |
On Sun, Jun 23, 2013 at 12:39 PM, <christhecomic@gmail.com> wrote: > 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
[toc] | [prev] | [next] | [standalone]
| From | Steven D'Aprano <steve+comp.lang.python@pearwood.info> |
|---|---|
| Date | 2013-06-23 03:08 +0000 |
| Message-ID | <51c666a9$0$29999$c3e8da3$5496439d@news.astraweb.com> |
| In reply to | #48964 |
On Sat, 22 Jun 2013 19:39:30 -0700, christhecomic wrote:
> 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.
--
Steven
[toc] | [prev] | [next] | [standalone]
| From | Gene Heskett <gheskett@wdtv.com> |
|---|---|
| Date | 2013-06-22 22:49 -0400 |
| Message-ID | <mailman.3822.1372164608.3114.python-list@python.org> |
| In reply to | #48964 |
On Saturday 22 June 2013 22:46:51 christhecomic@gmail.com did opine:
> 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%20Has%20America%20Become.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.
[toc] | [prev] | [next] | [standalone]
| From | Ian Kelly <ian.g.kelly@gmail.com> |
|---|---|
| Date | 2013-06-25 13:05 -0600 |
| Message-ID | <mailman.3842.1372187160.3114.python-list@python.org> |
| In reply to | #48964 |
On Sat, Jun 22, 2013 at 8:49 PM, Gene Heskett <gheskett@wdtv.com> wrote: > On Saturday 22 June 2013 22:46:51 christhecomic@gmail.com did opine: > >> 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. It's not working for me. >>> ''.join(chr(ord(c) & 0xdf) for c in 'ναί') == 'ΝΑΊ' False >>> ''.join(chr(ord(c) & 0xdf) for c in 'ναί') '\x9d\x91\x8f'
[toc] | [prev] | [next] | [standalone]
| From | Tim Rowe <digitig@gmail.com> |
|---|---|
| Date | 2013-06-25 20:26 +0100 |
| Message-ID | <mailman.3843.1372188395.3114.python-list@python.org> |
| In reply to | #48964 |
[Multipart message — attachments visible in raw view] — view raw
On 23 June 2013 03:49, Gene Heskett <gheskett@wdtv.com> wrote: > On Saturday 22 June 2013 22:46:51 christhecomic@gmail.com did opine: > > > 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 > 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). -- Tim Rowe
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web