noob question Letters in words?
Rob Cowie
cowie.rob at gmail.com
Fri Oct 7 21:33:24 EDT 2005
A string can be thought of as a tuple of characters. Tuples support
membership testing thus...
choice1 = raw_input("> ")
if '1' or 's' or 'S' in choice1:
#do something
elif '2' or 'e' or E' in choice1:
#do something
It doesn't seem to me to be a good idea; If the input is 'Start',
option1 is executed, likewise if the input is 'Stop', or any other
string with 's' in it.
Perhaps a better idea is to present the user with a choice that cannot
be deviated from, along the lines of...
def main():
print "1.\tStart"
print "2.\tSomething Else"
print "3.\tStop"
x = raw_input()
if x is '1': print 'Start'
elif x is '2': print 'Something else'
elif x is '3': print 'End'
else: main()
More information about the Python-list
mailing list