Python Program to Check Prime Number

Created with Sketch.

Python Program to Check Prime Number

Prime numbers:

A prime number is a natural number greater than 1 and having no positive divisor other than 1 and itself.

For example: 3, 7, 11 etc are prime numbers.

Composite number:

Other natural numbers that are not prime numbers are called composite numbers.

For example: 4, 6, 9 etc. are composite numbers.

See this example:

  1. num = int(input(“Enter a number: “))
  2. if num > 1:
  3.    for i in range(2,num):
  4.        if (num % i) == 0:
  5.            print(num,“is not a prime number”)
  6.            print(i,“times”,num//i,“is”,num)
  7.            break
  8.    else:
  9.        print(num,“is a prime number”)
  10. else:
  11.    print(num,“is not a prime number”)


Python Condition And Loops5


Leave a Reply

Your email address will not be published. Required fields are marked *