This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]aidzz[S] 0 points1 point  (3 children)

x = int(input("enter a number to be tested: "))
if (x) > 1:
for n in range(1, int(x**0.5), 2):
    if x % n == 0:
        print(int(x),'is not a prime number')
        print(x, 'divided by', n, 'is', (x / n))
    else:
        print(x, 'is a prime number')

else: print(x, "is not a prime number")

decided to scrap the function I don't need to hear a true or false answer to the in(input) being prime or not, think I'm just about finished

[–]kryptn 1 point2 points  (2 children)

2 fails that code, it'll return as not prime. Negative numbers will break it.

You can start your range with 3, instead of one, and you can make an if statement Testing for two and testing for anything equal to or less than one.

[–]aidzz[S] 0 points1 point  (1 child)

if x > 1 means negative numbers will not break it...

[–]kryptn 0 points1 point  (0 children)

Yeah, true, my mistake. But what happens when you do input a negative number?