Program to check if the given number is prime number in Python


In this section of python programing, we will understand the python to check whether the given number is prime or not. A prime no is the positive integer which is divisible by 1 or number itself.



num = int(input("Please enter the number to check: "))
if num > 1:
    for i in range(2, num):
        if (num%i) == 0:
            print("The number is not prime!")
        print("The number is prime number")
    print("The number is not prime!")




In the above python code we have created a variable num which stores integer input from user. After that if condition checks whether the input is positive integer of or not and in case the condition satisfies the for loop iterates from 2 to num/2. If the num given is divided by any other number then the number is not prime otherwise the number is prime.

Leave a comment

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