Python Program to check number is prime or not using a function


In this program, You will learn how to check number is prime or not using a function in Python.


Some list are: 2, 3, 5, 7, 11, 13

Example: How to check number is prime or not using a function in Python.

def check_prime(n):
    i = 2
    p = 1

    while i < n:
        if n % i == 0:
            p = 0
            break
        i = i + 1

    return p


x = int(input("Enter a number:"))
p = check_prime(x)

if p == 1:
    print("Number is prime:", x)
else:
    print("Number is not prime:", x)

Output:

Enter a number:13
Number is prime: 13