1 2 3 4 5 6 |
while True : try : x = int ( input ( "Please enter a number: " )) break except ValueError or x> 10 : print ( "Oops! That was no valid number. Try again..." ) |
I added in the "or x>10" as I need to keep the number below 10.
The data validation should be before the except ValueError step. How can I add the additional criterion?
Thanks.
P/S
Realised a backdoor to my problem.
1 2 3 4 5 6 7 |
while True : try : x = int ( input ( "Please enter a number: " )) if x < 10 : break except ValueError or x> 10 : print ( "Oops! That was no valid number. Try again..." ) |