Input number and check prime or not using for loop in Python
for Loop - Question 10
In this question, we will see how to input a number and check if it is a prime number or not in Python programming using for loop. To know more about for loop click on the for loop lesson.
Q10) Write a program in Python to input a number and check if it is a prime number or not using for loop.
Program
fc=0
n=int(input('Enter a number '))
for i in range(1,n+1):
if n%i==0:
fc=fc+1 # counting the factors of the given number
if fc==2: # a prime number has only two factors
print('Prime Number')
else:
print('Not Prime Number')
Output
Enter a number 17 Prime Number