This Python program checks whether a given number is a prime number or not. A prime number is a perfect natural number that can only be divisible by itself and by 1. This Python program checks the factors using the for loop and conditional statement and prints the desired output.
Program:
#Variable definition and assignment
inputn = 3
#Taking user input
#inputn = int(input("Enter a number: "))
if inputn > 1:
# check for factors
for i in range(2,inputn):
if (inputn % i) == 0:
print(inputn,"is not a prime number.")
print(i,"times",inputn//i,"is",inputn)
break
else:
print(inputn,"is a prime number.")
#If the input number is less than or equal to 1, then it is not prime
else:
print(inputn,"is not a prime number.")
Program Output:
3 is a prime number.
50 is not a prime number. 2 times 25 is 50