Python program to check prime number
In this example, we will learn how to check if a number is a prime number.
A Prime number is greater than 1 and should not be another factor except 1 and the number itself.
This means any number which can not be divisible by any other number except 1 and itself will be called a Prime number.
#python program to check prime number
n=int(input(“Enter number to check prime : “))
flag=0
if(n == 0 or n == 1):
  flag = 1
 Â
for i in range (2,n):
  if (n % i == 0):
    flag = 1
    break
if(flag == 0):
  print(‘ {0} is a prime number.’.format(n))
else:
  print(‘ {0} is not a prime number.’.format(n))
Output
Enter number to check prime : 5
5 is a prime number.
Python Program to add two numbers
Python program to find Area of Square
Python program to find Area of Triangle
Python program to swap two variables
Python program to convert Celsius to Fahrenheit
Python program to generate Random Number
Python program to convert Miles to Kolometers
Python program to find Largest of 2 numbers
Python program to check if number is Odd or Even
Python program to check if number is Positive Negative or Zero
Python program to check Leap Year
Types of Loop in Python
Python program to check Prime Number
Python program to Calculate Sum of N Natural Numbers
Python program to find sum of All Even Number between 1 to 10
Python program to find sum of All Odd Number between 1 to 10
Python program to check Armstrong Number