Basically, I have a "raw_input" then an "if" statement and then many "elif" statements after it. If the user inputs invalid data I want the "else" to print a string, then restart the program so the user can try again. How can I do this?
Asked
Active
Viewed 730 times
-3
-
Wrap your logic in a loop. – juanpa.arrivillaga Jan 12 '17 at 22:44
-
use `while True` loop to repeat your code. And `break` to leave this loop. – furas Jan 12 '17 at 22:44
1 Answers
1
Put your code in a loop:
while True:
# Code here
To exit the loop, use break
, which will also quit the program.
while True:
# Code here
if running == False: # The condition for breaking is up to you, if you're using one
break

Anthony Pham
- 3,096
- 5
- 29
- 38