Python program to Detect Prime Numbers

import math
x = int(input("Insert any number to check: "))
if x<2:
 print("Please, insert number greater than or equal to 2")
 quit()
elif x == 2:
 print("This is a prime number!")
 quit()
y = 2
num = int(math.sqrt(x))
while y <= num:
 if x%y == 0:
  print("This is NOT a prime number")
  quit()
 y += 1
print("This is a prime number")

 

 

Output:

Insert any number to check: 123
This is NOT a prime number

 

Insert any number to check: 11
This is a prime number

Subscribe For Daily Updates