Prime Number Checker

Write a Python function that takes a number as a parameter and checks if the number is prime or not. Return True if the number is prime, otherwise return False.

Example 1:

Input: 5 
Output: True

Example 2:

Input: 4 
Output: False

A prime number is a number that has only two distinct positive divisors: 1 and itself.

def check_prime(num):
    if num > 1:
        for i in range(2, num):
            if (num % i) == 0:
                return False
                return True
    return False

© Let’s Data Science


Unlock AI & Data Science treasures. Log in!