Program to check whether the number is a prime number.

In this python if else program, we will check whether an number is a prime number or not.

A prime number is a whole number greater than 1 that cannot be exactly divided by any whole number other than itself and 1.

Hint:
Use for loop with the range function and use if statement inside the loop

Steps to solve the program
  1. Take a number as input through the user and create a variable count and assign its value equal to 0.
  2. Use for loop with the range function to iterate over 2 to the given number.
  3. During the iteration check if any number divided the given number then add 1 to the count variable using if-else statement.
  4. If value of the count variable is greater then 0 then it is not a prime number.
  5. Print the respective output.
				
					# Take input through the user
num =  int(input("Enter a number: "))
# Create count variable
count = 0
# Iterate over numbers
for i in range(2,num):
# Check for division
    if num%i == 0:
    # Add 1 to the count variable
        count += 1
# Check for prime number        
if count > 0:
# Print output
    print("It is not a prime number")
else:
#Print output
    print("It is a prime number")
				
			

Output :

				
					Enter a number: 59
It is a prime number
				
			

Related Articles

print the square of the number if it is divided by 11.

check given number is odd or even.

Leave a Comment