- The condition to check the given number is prime or not is the number is only divisible by one and by itself.
Program :
# Program to check the given number is prime or not
def checkingPrime(num):
prime = True
for i in range(2, num):
if num%i == 0:
prime = False
# multiply and divide by i
value = f"{i} times {num // i} is {num}"
print(value)
break
else:
prime = True
return prime
num = int(input("Enter number: "))
if num > 1:
if checkingPrime(num):
print(f"{num} is a prime number")
else:
print(f"So, {num} is not a prime number")
else:
print("The number must be greater than 1")
Output :
Comments