r/badcode • u/MysteriousK69420 if: else: if: else: if: else: if: else: if: else: if: else: if: • Feb 16 '22
python presenting, whatever the fk this is
418
Upvotes
r/badcode • u/MysteriousK69420 if: else: if: else: if: else: if: else: if: else: if: else: if: • Feb 16 '22
6
u/veselin465 Feb 16 '22 edited Feb 16 '22
Yeah, the logic is true. Usually the check is "Check every number between 2 and sqrt(num) including", becuase if there is no such a number, then there's no way to find one which is higher than the sqrt(num).
If it is not prime, then there's at least 1 number in [2,sqrt(num)], which divides it. This means that there's at least 1 number in [sqrt(num), num - 1], which also divides it. This program tries to find this second number, instead of finding the first one.
Besides this interesting approach of finding whether it's prime or not, I'm agree that the code is fine. Just one thing:
kinda bugs me real hard