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

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -