0
Bugs or improvements
Can you find bugs in my code? Or any improvements? Tyvm! https://sololearn.com/compiler-playground/cuE6D2TpR1sD/?ref=app
5 Respuestas
+ 1
Emptynew Account ,
I noticed you used exit() without importing sys, which I thought you had to do, so I looked it up.
There are two. The one you used is from the site module. The site module is automatically imported every time, and "adds several constants to the built-in namespace." However, it goes on to say that those constants "are useful for the interactive interpreter shell and should not be used in programs."
It probably doesn't matter in a small program like this, but I'm guessing it's something to avoid doing in any professional work.
site module
https://docs.python.org/3/library/constants.html#constants-added-by-the-site-module
sys module
https://docs.python.org/3/library/sys.html#sys.exit
+ 1
Rain Thanks for those comments. I will have a look in my code!
+ 1
Rain, I had a look at the modules. You are right. I thought of some ways to remove the exit() by using a for loop with a break inside of it. Sadly Sololearn doesn't ask for multiple inputs. I guess my codes in Sololearn must use the exit or return function to terminate loops.
0
Emptynew Account ,
I think your program is misnamed. "Prime number checker" implies that it will check if the user's number is prime. But it doesn't do only that.
I think it should be named Prime Factorization, since, for most numbers (most numbers are composites), it produces a list of primes whose product is the user's number.
Nice work.
I would add one thing. Print the user's number too. Since you destroy it, you'll have to make a copy first.
0
Emptynew Account ,
I didn't mean remove exit().
I meant sys.exit() is OK but site.exit() is supposedly not OK, and if you use exit() alone without importing sys, you're using site.exit() because site is automatically imported.
(The news was news to me too, but I heed when python.org says "should not be used in programs" even if I don't know the repercussions.)
I often use sys.exit().
import sys
try:
raise ValueError
except ValueError:
sys.exit()
And yeah, it is unfortunate that the playground isn't interactive for most languages. I notice that the Web programs (containing three tabs for HTML CSS JS) can be interactive though.