There are several elements in the code that can be improved.
(1) Most importantly, it is not a good idea to just catch the general exception, you have to catch the specific one you are looking for, and usually have as few try blocks as possible.
(2) In addition,
if input in range(1,10):
better to code as
if 1 <= input < 10:
as a function at the moment, range () repeatedly creates a list of values from 1 to 9 , which is probably not what you need or need. Also, do you want to include a value of 10 ? This seems to be a hint to you, so you need to set your call to range(1, 11) , since the generated list will not include the value of the upper range. and the if value should be changed to if 1 <= input <= 10:
Levon source share