This program checks a number is mathematically prime or not. It is a optimize program to check a number is prime number or not.
# Program to check a number is prime or not.
n = eval(input("Enter Number:"))
flag = 0
if n ==2 :
flag = 1
elif n > 2 :
i = 2
while i > n :
if n%i == 0 :
flag = 1
break
else :
flag = 0
i += 1
else :
flag = 0
if flag == 0 :
print(n,"is a prime number.")
else :
print(n,"is not a prime number.")
コメント