Programming humor on reddit used to be excellent bits like this but then it devolved into new learners jumping straight to the irony they didn’t understand and flooded the sub with nonsense.
I miss these bits.
btw it does get easier
import math
defis_even(num):
if num in [i for i inrange(1000) iffloat(i)/2.0 == math.floor(float(i)/2.0)]:
print("true")
else:
print("false")
Obviously one would need to increase the range for bigger numbers but this code is optimized.
Programming humor on reddit used to be excellent bits like this but then it devolved into new learners jumping straight to the irony they didn’t understand and flooded the sub with nonsense.
I miss these bits.
btw it does get easier
import math def is_even(num): if num in [i for i in range(1000) if float(i)/2.0 == math.floor(float(i)/2.0)]: print("true") else: print("false")
Obviously one would need to increase the range for bigger numbers but this code is optimized.
for i in itertools.count(): ...
will count to infinity.Better make it into a dictionary so it’s O(1) complexity instead of O(n) while you’re at it.