Python keep asking for raw_input in "while True" -
this question has answer here:
i need python keep asking raw_input if answer different 1 or 2.
here example:
print """what want me do? 1) press 1 if want ..... 2) press 2 if want .....""" while true: answer1 = raw_input(" => ") if (answer1 == 1): .... .... elif (answer1 == 2): .... .... elif (answer1 != 1 or 2) or answer1.isalpha(): print "i need 1 or 2"
the problem python keeping asking raw_input if user enter 1 or 2. wrong?
you should put break
statement in if
, elif
block if answer 1
or 2
break out of while loop.
example -
if (answer1 == 1): .... .... break elif (answer1 == 2): .... .... break
Comments
Post a Comment