-1

i'm trying to figure out how to exclude certain numbers (numbers that aren't prime) in my program. For example, I don't want 15 to be printed so I used the modulo to exclude numbers divisible by 5 but that eliminates 5, which is a prime number. Any help on how to code this would be huge help! Thank you...

start = int(input("Start number: "))
end = int(input("End number: "))

while start < 0 or end < 0:
    print ("Start and end number must be positive. Try again.")
    start = int(input("Start number: "))
    end = int(input("End number: "))

while start > end:
    print ("End number must be greater than start number. Try again.")


for x in range (start, end):
    is_prime = True

for x in range (start, end):
    trial = x % 2
    trial1 = x % 5
    trial2 = x % 3
    if trial != 0 and trial1 != 0 and trial2 != 0:
        print (x, "is a prime number")
        x = x + 1
    else:
        is_prime = False
Danny Garcia
  • 227
  • 3
  • 19

3 Answers3

0

You can create a list of numbers you want to use in your loop let's call it loop_list and then simply use for x in loop_list, that avoid you setting up exclusions

Alessandro
  • 845
  • 11
  • 21
0

If you want to be sure that N is a prime number, you have to check for all number to squareroot(N) if N%number != 0.

Are you looking for optimisation? If no, you just need that.

Whitefret
  • 1,057
  • 1
  • 10
  • 21
0

You can try this prime number logic :-

def check_prime(num):
    notPrimeFlag = 'N'
    for i in range(2, num):
        if num % i == 0:
            notPrimeFlag = 'Y'
            break
    if notPrimeFlag == 'N':
        print("Prime number")
Sourav
  • 496
  • 2
  • 12
  • 28