Home >>Python Programs >Python Program to Check Prime Number
In this example, we will see a python program to check if the given input number is a prime number or not.
A prime number is a natural number greater than 1 which has no positive divisor other than 1 and itself. Like 3, 7, 11 etc. are prime numbers.
Other natural numbers that are not a prime number are called as composite numbers. Like 4, 6, 9 etc. are composite numbers.
Example :
num = int(input("Enter a number: "))
if num > 1:
for i in range(2,num):
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")
else:
print(num,"is not a prime number")