I started to write a program asking an input (integer). I would like to raise two kinds of exceptions : first, in case of numbers are out of range and second, in case of inserted data is not an integer. The problem appears when two wrong insertions are done one by one. This code can handle only one error, without repetitions. How to modify it and put 'raise/exception' in some kind of loop working infinite number of times?
print('It is a program generating and sorting wide range of numbers')
a = 'Insert a start value: '
b = 'Insert a stop value: '
c = 'Insert a step value: '
class CustomError(Exception):
pass
def insert(msg):
my_input = int(input(msg))
if my_input >= 100:
raise CustomError('Input must be smaller than 100')
return my_input
try:
start = insert(a)
stop = insert(b)
step = insert(c)
except ValueError as number:
print('value must be an integer')
except CustomError as data:
print(data)
start = insert(a)
stop = insert(b)
step = insert(c)
try:
start = insert(a)
stop = insert(b)
step = insert(c)
except ValueError as number:
print('value must be an integer')
except CustomError as data:
print(data)