Aug-11-2021, 09:58 AM
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...")Copied from python.org.
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.
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...")Any better or proper way to solve this? Thanks.