I have this code but it does not work very well, that is, if it is integer at first numOfValues
is correct, but if not it is with type None
, since what is in memory is the first input ( which is not integer). I would like, regardless of the attempts you make, numOfValues
would always have the value of the last input, and the function would stop when you entered an integer, so it would be numOfValues = INT
(when the function returns x
)
def return_int():
x = raw_input("Number of names to insert?\n")
try:
int(x)
return int(x)
except ValueError:
print "must be an integer"
return_int()
numOfValues = return_int()
print numOfValues
...