Destide@feddit.uk to Programmer Humor@lemmy.mlEnglish · 2 months agoInfallible Codelemmy.mlimagemessage-square92fedilinkarrow-up1341arrow-down116
arrow-up1325arrow-down1imageInfallible Codelemmy.mlDestide@feddit.uk to Programmer Humor@lemmy.mlEnglish · 2 months agomessage-square92fedilink
minus-squareEuphoma@lemmy.mllinkfedilinkEnglisharrow-up21·2 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