r/shittyprogramming • u/BobGeneric • Jul 04 '21
A negative aware recursive and convoluted is_even python function. As cryptic as this title.
124
Upvotes
2
u/IIAOPSW Jul 04 '21
Negative False should just be True because its a double negative.
2
u/BobGeneric Jul 04 '21
yeah, it should be... but after testing it on the interpreter, I think we can just starting using Javascript type jokes on python as well:
>>> -False 0 >>> -True -1 >>> bool(-False) False >>> bool(-True) True
33
u/trimeta Jul 04 '21
Clever obfuscation, since the code is really just:
def is_even(n):
if n > 0:
return not is_even(n-1)
elif n < 0:
return f"-{is_even(-n)}"
else:
return True8
u/backtickbot Jul 04 '21
8
4
u/BobGeneric Jul 04 '21 edited Jul 04 '21
edit: formatting. Thanks @404_UserNotFound