To check prime number in python programming, you should have the knowledge of the following topics:

- Prime number
- Python if…else Statement
- Python for Loops

## Method One: Python If … Else statement

# Python Code to Check Prime Number

#Variable definition and assignment

a = 3

#Taking user input

#a = int(input(“Enter a number: “))

if a > 1:

# check for factors

for i in range(2,a):

if (a % i) == 0:

print(a,”is not a prime number.”)

print(i,”times”,a//i,”is”,a)

break

else:

print(a,”is a prime number.”)

#If the input number is less than or equal to 1, then it is not prime

else:

print(a,”is not a prime number.”)

Output

3 is a prime number.

Nice

Thanks