Destide@feddit.uk to Programmer Humor@lemmy.mlEnglish · 6 months agoInfallible Codelemmy.mlimagemessage-square27linkfedilinkarrow-up16arrow-down10
arrow-up16arrow-down1imageInfallible Codelemmy.mlDestide@feddit.uk to Programmer Humor@lemmy.mlEnglish · 6 months agomessage-square27linkfedilink
minus-squareEuphoma@lemmy.mllinkfedilinkEnglisharrow-up2·6 months agodef even(n: int) -> bool: code = "" for i in range(0, n+1, 2): code += f"if {n} == {i}:\n out = True\n" j = i+1 code += f"if {n} == {j}:\n out = False\n" local_vars = {} exec(code, {}, local_vars) return local_vars["out"] scalable version
def even(n: int) -> bool: code = "" for i in range(0, n+1, 2): code += f"if {n} == {i}:\n out = True\n" j = i+1 code += f"if {n} == {j}:\n out = False\n" local_vars = {} exec(code, {}, local_vars) return local_vars["out"]scalable version