Destide@feddit.uk to Programmer Humor@lemmy.mlEnglish · 17 days agoInfallible Codelemmy.mlexternal-linkmessage-square164fedilinkarrow-up1489arrow-down126
arrow-up1463arrow-down1external-linkInfallible Codelemmy.mlDestide@feddit.uk to Programmer Humor@lemmy.mlEnglish · 17 days agomessage-square164fedilink
minus-squarekryptonianCodeMonkey@lemmy.worldlinkfedilinkarrow-up21·edit-217 days agodef is_even(num): if num == 1: return False if num == 2: return True raise ValueError(f'Value of {num} out of range. Literally impossible to tell if it is even.')
minus-squareVitabytesDev@feddit.nllinkfedilinkarrow-up6·edit-216 days agodef is_even(num): num = num & 1 if num == 0: return False if num == 1: return True raise ValueError(f'what the fuck') EDIT: forgor to edit the numbers
minus-squarekryptonianCodeMonkey@lemmy.worldlinkfedilinkarrow-up10·16 days agoIf you’re waiting for “num & 1 == 2”, you’re going to be very disappointed
def is_even(num): if num == 1: return False if num == 2: return True raise ValueError(f'Value of {num} out of range. Literally impossible to tell if it is even.')
def is_even(num): num = num & 1 if num == 0: return False if num == 1: return True raise ValueError(f'what the fuck')
EDIT: forgor to edit the numbers
If you’re waiting for “num & 1 == 2”, you’re going to be very disappointed