[Tutor] func-question_y_n.py

Christopher Emery cpe.list at gmail.com
Sun Mar 17 01:22:35 CET 2013


Hello Alan and Mark,

Thank you, I didn't realize that it was not needed, I had seen some
other code on the net that showed it with, however its like the if or
for statement they don't need () thank you.  Thanks Alan for your tip,
once I had my code working in the best way I was going to add the
.lower() I had seen it used in another person post and figured that
would assist me in getting a mixed of typed word of yes/YES/...

Thanks again it is appreciated!

On Fri, Mar 15, 2013 at 9:06 PM, Alan Gauld <alan.gauld at btinternet.com> wrote:
> On 15/03/13 23:37, Christopher Emery wrote:
>>
>> so I may understand the why to your statement "
>
>
>> WHy the unneeded parenthesis?
>
> Mark was pointing out that parentheses are not needed in a while statement.
> So why add them? They just add visual clutter.
>
>> What about 'yes'?"
>
>
> And here he was alluding to the fact that your code requires a capitalised
> 'Yes', but in practice it should be OK to enter
> lower case, or even all caps, input too.
>
> ie.
> yes
> Yes
> YES
>
> should all be valid
>
> and yES, yeS and yEs won't be too bad either.
>
> The solution is usually to convert input to all
> lower (or upper) before checking its value.
>
> answer = input(question).lower()
>
> Now we can test for 'yes' regardless of what combination
> of case the user actually typed.
>
> HTH,
> --
> Alan G
> Author of the Learn to Program web site
> http://www.alan-g.me.uk/


More information about the Tutor mailing list