I came across some weirdness in Python using a function similar to the following:
def foo(x):
if int(x)!=4:
x = raw_input("Wrong guess, please enter new value: " )
foo(x)
else:
print "Good Job! %s was right"%x
return x
value = foo(x=raw_input("Guess a Number between 1 and 10: "))
print value
If I enter, for instance: "1" then "2" then "3" then "4", I get the following printed out:
Good Job! 4 was right
2
This is confusing, since it seems the function is successfully identifying the right answer, but after doing so it is returning a value that was the 2nd response given, instead of the most recent response.
Can anyone explain what's going on with the binding of "x" in this recursive function?