[Tutor] Trouble executing an if statement with a string fromaninput
Alan Gauld
alan.gauld at btinternet.com
Mon Apr 18 11:34:01 CEST 2011
"Peter Otten" <__peter__ at web.de> wrote
>>> x = input("a, b, or c:")
>>> ...
> If she were using 2.x and typed an 'a' she would get a NameError.
Oops, too early in the morning.
For some reason I thought she was using numbers... Doh!
>> If you want your code to work in both Python
>> versions you could explicitly convert the input()
>> result to a string:
>>
>> x = str(input("a, b, or c:"))
>
> str() doesn't magically uneval.
Nope, again it would only work with numbers!
Sorry folks, I'll drink a coffee before answering posts in future! :-)
--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/
More information about the Tutor
mailing list