Answers for "prime number function in python"

7

determine if number is prime python

# Time Efficient Primality Check in Python

def primeCheck(n):
    # 0, 1, even numbers greater than 2 are NOT PRIME
    if n==1 or n==0 or (n % 2 == 0 and n > 2):
        return "Not prime"
    else:
        # Not prime if divisable by another number less
        # or equal to the square root of itself.
        # n**(1/2) returns square root of n
        for i in range(3, int(n**(1/2))+1, 2):
            if n%i == 0:
                return "Not prime"
        return "Prime"
Posted by: Guest on September-17-2020
2

get prime number python

from num_tool import is_prime
print(is_prime(3))

#returns True because 3 is a prime
Posted by: Guest on September-13-2021
3

prime number in python

import math
a=[i for i in range(2,int(input('prime number range'))) if 0 not in [i%n for n in range(2,int(math.sqrt(i)))]]
print(a)
Posted by: Guest on June-18-2021
0

how to check if a number is prime in python

import math
def prime(x):
    if x == 2 or x == 3 or x==5:
        return True
    if x == 1 or x == 4:
        return False
    num = 2
    a= math.sqrt(x)+4 
    while a > num:
        if x % num == 0:
            return False
        else:
            num = num + 1
    return True
Posted by: Guest on September-19-2020
0

prime number using python

# Prime number checker

def is_prime(num):
    for i in range(2,num):
        if (num % i) == 0:
            return False
    return True
    
num = int(input("Enter a number:"))
check_prime = is_prime(num)

if check_prime:
    print("Your number is a prime")
else:
    print("Your number is not a prime ")
Posted by: Guest on November-13-2021

Code answers related to "prime number function in python"

Python Answers by Framework

Browse Popular Code Answers by Language