A Program to Check Prime Number

In this example, we are giving a program to check whether an integer is a prime number or not.


Program to check prime number:

  1. # Check whether an integer is a prime number or not
  2. num = int(input('Enter a number: '))
  3. if num > 1 :
  4. for i in range(2,num):
  5. if (num % i) == 0:
  6. print(num,"is not a prime number")
  7. print(i,"times",num//i,"is",num)
  8. break
  9. else:
  10. print(num,"is a prime number")
  11. else:
  12. print(num,"is not a prime number")

Output:

Enter a number: 442
442 is not a prime number
2 times 221 is 442