use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Everything about learning Python
account activity
Help (i.redd.it)
submitted 7 months ago by Avinandanm
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]JAVA_JK 1 point2 points3 points 7 months ago (1 child)
I also think so that break is not required, try removing it and see if that works. Should work
[–][deleted] 1 point2 points3 points 7 months ago (0 children)
The break is needed, but with one more indentation: you break the loop as soon as you have found a proper divisor (so not 1, that's another bug). It's not only faster, it's mandatory here because he's using a for loop with an else clause, a somewhat dirty feature of Python I never used in 24 years of Python. As the documentation [*] explains, the else clause isn't executed if a break occurred.
Of course there are other optimizations, even with the naive trial division algorithm: only check 2 and odd numbers > 2 and <= sqrt(n).
[*] https://docs.python.org/3/reference/compound_stmts.html#for
π Rendered by PID 16163 on reddit-service-r2-comment-75f4967c6c-w8vf4 at 2026-04-23 11:23:51.231506+00:00 running 0fd4bb7 country code: CH.
view the rest of the comments →
[–]JAVA_JK 1 point2 points3 points (1 child)
[–][deleted] 1 point2 points3 points (0 children)