def isEven(x):
if x == 0:
return True
elif x == 1:
return False
else:
return not isEven(x-1)
Just don't try doing it on numbers greater than 994 or smaller than 0!
Explanation:
You can't call this function on any numbers smaller than zero, becuase any input that isn't 0 or 1 results in the function being called on a smaller number. If the first call of the function is on a negative number, subtracting one from it is clearly never going to lead to it being 0 or 1, so the function will endlessly call itself, the recursive equivalent to an infinite loop. However, you could modify this function to allow it to work for negative inputs - this is left as an exercise to the reader!
You can't call it on numbers greater than 994 (or thereabouts (or rather numbers greater than, equal to or slightly less than the recursion depth)) because it causes a StackOverflow
error (described as a RuntimeError: maximum recursion depth exceeded
). To understand what this means, you will need to understand recursion (and in order to understand recursion, you need to understand recursion, as the old joke goes). Or you could look at useful resources like this and this.