Python Program to Check Prime Number

Here you will get python program to check prime number.

A number is called prime number if it is only divisible by 1 or itself. For example 2, 3, 5, 7, 11, etc are prime numbers.

Below program takes a number as input and checks it is prime number or not.

Python Program to Check Prime Number


enter a number: 11
prime number

Comment below if you have any queries related to above python prime number program.

3 thoughts on “Python Program to Check Prime Number

  1. Pavan Kumar

    Here according to the program else is inside the for loop. When the if condition fails, directly it will print as the number is not prime until checking up to the last value. If I take num=9, then in first iteration (9%2)==0 (false) else statement will be executed. But 9 is not prime right. can u explain me this prgm.

    1. Admin Post author

      See, this else is not the part of if. In python for loop is little different from other languages like C and C++. In python we can use a else statement with for loop. After the loop ends, else statement is executed. In case break is used somewhere in loop then else is not executed. The program is correct and works fine, just try to run it.

      You can learn about for loop in python here

  2. Soham

    def prime_check(number= ‘Plese enter a valid number’):
    for s in range(2,number+1):
    if number<=1 or number / s != 0:

    print("it's not a prime number")

    print("It's a prime number")


Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.