In this program, we will check whether a number is a Prime number or not.
Steps to solve the program
- Take a number as input through the user and create a count variable and assign its value equal to 0.
- Use for loop with the range function to check whether a number is a prime number or not.
- If a number divides the input number then add 1 to the count variable.
- If a number is divisible by 1 and by itself then it is a prime number.
- 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