0
num = int(input("Enter a number: "))
if num==0 or num<0:

    continue
else:
    if num > 1:

       if (num % i) == 0:
           print(num,"is not a prime number")
           print(i,"times",num//i,"is",num)
           break
   else:
       print(num,"is a prime number")

Edited by pyTony: code reformat

3
Contributors
2
Replies
23
Views
2 Years
Discussion Span
Last Post by sneekula
0

Generally:

# show prime numbers
# prime numbers are only divisible by unity and themselves
# (1 is not considered a prime number)

for n in range(2, 100):
    for x in range(2, n):
        if n % x == 0:
            # found a factor
            #print(n, 'equals', x, '*', n/x)  # optional
            break
    else:
        # note this else has to line up with second for, not the if
        # means loop fell through without finding a factor
        print(n, 'is a prime number')
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.