Write a Python function that takes a number as a parameter and check the number is prime or not

Introduction

Write a Python function that takes a number as a parameter and check the number is prime or not. I have used python 3.7 compiler for debugging purpose.

def test_prime(num):
    if (num==1):
        return False
    elif (num==2):
        return True;
    else:
        for x in range(2, num):
            if(num % x==0):
                return False
        return True             
print(test_prime(167))

Result

Write a Python function that takes a number as a parameter and check the number is prime or not
Write a Python function that takes a number as a parameter and check the number is prime or not

Leave a Comment