I have a task
Print the minimal value from list you entered. First entered value defines the length of the list. Each next value should be placed in list one by one. Use operator for.
n
is defined before, by input and start_n = 1
def list2_func():
global list2
list2 = []
for i in xrange(start_n, n + 1):
list2.append(raw_input('Enter the %s number: ' % i))
list2_check()
def list2_check():
global start_n
try:
value = int(list2[-1])
except ValueError:
print "Please use only 0-9 keys. Re enter %s number" % len(list2)
start_n = len(list2)
list2_func()
else:
start_n = start_n + 1
Everytime I enter any key which is not passing the try
it asks for same value again - which is great. But when I enter my last value (for example n = 4
, so 4th value) program asks me again to input. At the end I got 2*n - 1
amount of values - which is not what i want.
Could you please suggest me any another way to check if entered value is a number? Or point the mistake in my code!
I'm using python 2.7.