how to go back to first if statement if no choices are valid - python

Posted by wondergoat77 on Stack Overflow See other posts from Stack Overflow or by wondergoat77
Published on 2012-10-10T21:34:00Z Indexed on 2012/10/10 21:36 UTC
Read the original article Hit count: 361

Filed under:
|
|

how can i have python move to the top of an if statement if nothing is satisfied correctly

i have a basic if/else statement like this:

print "pick a number, 1 or 2"
a = int(raw_input("> ")

if a == 1:
    print "this"
if a == 2:
    print "that"
else:
   print "you have made an invalid choice, try again."

what i want is to prompt the user to make another choice for 'a' this if statement without them having to restart the entire program, but am very new to python and am having trouble finding the answer online anywhere.

© Stack Overflow or respective owner

Related posts about python

Related posts about if-statement