Check whether a number is a Prime number or not

In this program, we will check whether a number is a Prime number or not.

Steps to solve the program
  1. Take a number as input through the user and create a count variable and assign its value equal to 0.
  2. Use for loop with the range function to check whether a number is a prime number or not.
  3. If a number divides the input number then add 1 to the count variable.
  4. If a number is divisible by 1 and by itself then it is a prime number.
  5. Print the output.
				
					num = int(input("Enter a number: "))
count = 1

for i in range(2, num):
    if num%i == 0:
        count += 1

if count > 1:
    print("It is not prime number")
else:
    print("It is a prime number")
				
			

Output :

				
					Enter a number: 59
It is a prime number

Enter a number: 100
It is not prime number


				
			

calculate the factorial of a number

print all Prime numbers between 1 to n

Leave a Comment