This is very useless, because helps to make a good and clean code without too many error to fix, like this example:
while True:
try:
q=int(input(“Please enter a non-negative integer number: “))
break
except ValueError:
print(“this is not a integer number, try again: “)
while q<0:
try:
q=int(input(“this is not a positive number,try again: “))
except ValueError:
print (“this is not a integer number, try again: “)
while True:
try:
q=int(input(“Please enter a non-negative integer number: “))
break
except ValueError:
print (“this is not a integer number, try again: “)
Validated user input in Python by Pablo is licensed under a Creative Commons Attribution 4.0 International License.