I am making some homework drill and am trying to check whether a number is a positive integer using Try. somewhere along the way it returns the value of my input, but it returns the negative value, even after I eventually type in a valid value. lets say- first i typed in -10, it tells me to type again, then I type 2, but the return is still -10.
def takes_desicion(name):
print "Ok %s, now lets make a desicion what to do with your text.\n" %name
print "you can either- 1.leave it, 2.reverse it, or 3.make a new input."
while True:
try: #takes an input with exception- in this case, only integer.
desicion = int(raw_input("Hit your number to decide."))
print desicion
except ValueError:
print "Sorry, thats not a number."
continue
else: #if int is negetive, goes back to the function again, recursively
if desicion < 1:
print "That number is illegal."
takes_desicion(name)
break
return desicion
if i first input -10, and the second input is 2, i would expect the output (return) to be 2. but its -10. That's the value that returns from the function.