-1

I have developed a code to find a prime number using python. But it keeps saying the numbers are prime even tho they are not. I am new to python so my knowledge in syntax is really not as good

when i input the number 15 it would say it is a prime number. but it shouldn't be a prime number

a = 0
#num will be the number we are checking
x = int(num)
num = sqrt(float(num))
num = int(num)
primeCheck = True
for a in range(3, num, 2):
    if x == 1 or x == 2:
        primeCheck = False
        #not prime
    if x % a == 0:
        primeCheck = False
        #not prime
if primeCheck == true:
    #prime
2
  • this and this. Commented Jun 16, 2019 at 19:39
  • There are many answers in SO about that, why don't you check those before asking again? Commented Jun 16, 2019 at 19:40

1 Answer 1

0

You want x % a, not a % x. The larger number should almost always be on the left for the mod operation.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.