digits = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '0']
def inp():
inp = input('Enter a value: ')
for i in inp:
if i not in digits:
print('Please enter a value from 2 to 100')
inp()
n = int(inp)
if not 2 <= n <= 100:
print('Please enter a value from 2 to 100')
inp()
else:
return n
number = inp()
I am unable to make it foolproof: user can enter an empty string ""
or float, and it gives an error.
For example: If I enter 10.5
and then 10
then it shows error that 10.5 cannot be taken as integral value.
If there would be a simple function like val()
from VB6 or something equivalent for python, I would be very grateful.
Edit: Expected behaviour: I want the code to take only integral value, 2 to 100 as input, and if incorrect value is entered then it should repeat until an appropriate value is received.
Please help.