+ 2
what is the meaning of "return not" in this code?
def is_even(x): if x == 0: return True else: return is_odd(x-1) def is_odd(x): return not is_even(x) print(is_odd(17)) print(is_even(23)) output is true false why this false is coming?
3 Respostas
+ 2
There is no "return not". There is only return. "not" is a boolean operator that returns the boolean inverse of the value. In your code , is_odd fun returns " not is_even". Whatever is_even fun returns,"not" will reverse that. If is_even returns True, not will change it into False.
0
Because 23 is not even
0
Here's the same code with some suitable output, to help you understand the recursion:
https://code.sololearn.com/c3U3O9H1Q10e/?ref=app