The question is in the title: How do you go to the beginning of an if statement in the else section?
Code:
p1 = int(input())
if p1 <= 9 and p1 >= 1:
pass
else:
print('Invalid input. Please try again.')
p1 = input()
The question is in the title: How do you go to the beginning of an if statement in the else section?
Code:
p1 = int(input())
if p1 <= 9 and p1 >= 1:
pass
else:
print('Invalid input. Please try again.')
p1 = input()
Run in a loop and never break out until the input meets the criteria.
This code will throw an exception if you enter a value that cannot be converted to an
int
and terminate the program.To get around this catch the exception and carry on.