how to check if a number is prime in python

Solutions on MaxInterview for how to check if a number is prime in python by the best coders in the world

showing results for - "how to check if a number is prime in python"
Luca
12 Jan 2020
1# Time Efficient Primality Check in Python
2
3def primeCheck(n):
4    # 0, 1, even numbers greater than 2 are NOT PRIME
5    if n==1 or n==0 or (n % 2 == 0 and n > 2):
6        return "Not prime"
7    else:
8        # Not prime if divisable by another number less
9        # or equal to the square root of itself.
10        # n**(1/2) returns square root of n
11        for i in range(3, int(n**(1/2))+1, 2):
12            if n%i == 0:
13                return "Not prime"
14        return "Prime"
Hilary
25 Jan 2020
1import math
2def prime(x):
3    if x == 2 or x == 3 or x==5:
4        return True
5    if x == 1 or x == 4:
6        return False
7    num = 2
8    a= math.sqrt(x)+4 
9    while a > num:
10        if x % num == 0:
11            return False
12        else:
13            num = num + 1
14    return True
Delores
04 Sep 2016
1#make the function
2#to do this all hte vairibles go in side the function
3
4def CheckIfPrime ():
5    a1 = input("which number do you want to check")
6    a = int(a1)#you need the checking number as an int not an str
7    b = 2 #the number to check againts
8    c = ("yes")
9    while b < a:#run the loop
10        if a%b == 0:#check if the division has a remainder
11            c = ("no")#set the answer
12        b = b+1
13    print(c)#print the output
14CheckIfPrime ()#call the function  
15
Niklas
29 Aug 2016
1def is_prime(n: int) -> bool:
2    """Primality test using 6k+-1 optimization."""
3    if n <= 3:
4        return n > 1
5    if n % 2 == 0 or n % 3 == 0:
6        return False
7    i = 5
8    while i ** 2 <= n:
9        if n % i == 0 or n % (i + 2) == 0:
10            return False
11        i += 6
12    return True
13
queries leading to this page
chek if number is prime in pythonpython function to check for prime numbershow to create a def function in python that finds out if a number is primehow to check if number is prime in python 27prime number program pythonprime number code whether prime or not pythonprime number checking in pythoncheck if prime in python inbuiltis prime number algorithmprime number program in python using functionpython program for check prime numberfind prime numbers algorithm pythoncheck given number is prime or not in pythonhow to determines whether an integer is prime or composite pythonwrite a program to check if the given number is a prime or not in pythonpython check prime numebris a prime number program in pythondetect prime number pythonknow if a number is prime python without loopcheck if a number is a prime pythonwrite a python function that takes a number as a parameter and checks if the number is prime or not prime number using function in pythonprogram to find prime number in pythonget if prime in pythoncheck if prime number pythoninbuilt function to determine a prime number in pythonpython if n is primepython if the integer is primehow to find out if a number is prime in pythonprime number code in pythonpython code to find if a number is primehow to check if a number is prime on pythonprime number problem in pythonnon prime number in pythoncheck if prime algorithmhow to check if a number is prime or not in pythonhow to check number is prime in pythonpython prime numberspython find prime numberspython prime finderhow to solve prime numbers in pythonpython code to check if a number is primeprime check packets pythonhow to identify prime in pythonfind prime number in pythonprime number condition in pythonnumber is prime or not pythonpython module function to check prime numberpython chec if primepython program to find the given integer whether it is prime or notprime no in pythonsath ethoras prime number problem in pythonprime number algorithmcheck whether a number is prime or not in python with if elsepython code for prime or notcheck if the namber is prime in pythoncheck whether number is prime or not in pythonpython how to check if number is primehow to check number is prime or not in pythonchecking prime number in pythonfastest way to determine if a number is prime algorithmwap to check prime number in pythoncheck if a number is pprim ein pythonhow to check for prime numbers in pythonprime number or not in pythonpython program to check prime number in an arrayis a number prime pythoncheck if integer is prime pythnhow to figure out if a number is prime pythoncheck number is prime or not pythonpython check if number is a primeverify number prime python how to calculate prime numbers in pythonprime or not in pythondetermine if number is prime pythonfind if a number is primepython function to check prime numberpython check if a number is primecheck prime no in pythonfind if a number is prime pythonhow to write prime number in pythonhow to check if a number is prime pythoncheck if prime python mathwap that checks prime number in pythonpython program to check if a number is divisible by a primecheck prime number in pythonflask syntax for return prime number or not python determine if a number is primecheck if a number is prime number pythonfastest way to check if a number is prime pythonchecking prime or not in pythonif condition for prime number in pythonpython test for prime numberwrite a function to determine whether a certain number is a prime number or notprime number check algorithmprime or not prime pythonprime no pythonwrite an algorithm to find whether a number is prime or notpython short check primeprime number code pythonhow to check if a number is prime in python efficientlycheck if its prime number pythondef isprime 28number 29how to find a prime number in pythonis a prime numbers program in pythonhow to check if a number is prime python fastpython input number if prime number or notprogram to find whether a number is prime or not pythonhow to find if a number if prime or not in pythonprime numbers code pythonpython math check if primecheck prime number accept an integer check if the number is prime print the result e2 80 93 if the number if prime check prime number pythonpython program to check if 23 given number is prime or nohow to check number prime or not in pythoninput a number and check if it is prime or not in python0python program to check prime number in a arraycheck prime numer or not in pythonfind prime number as input 3d 5 in python check the given number is prime or not in pythonhow to check if a number if prime pythonpython code to see if a number is prime6 check whether a number is prime or not pythonpython program to check if a number is a prime number 3fcheck entered number is prime or not in pythonhow to determine a prime number pythonprime nunmber in pythonpython check prime numbera function to check if a number is prime in pythonpython test if primepython function check if prime numberhowto check if number is prime pythonfind prime numbers in pythonhow to program prime numbers in pythonhow to detect if a number is prime pythonpython how to determine prime numberpython to check prime numbern prime numbers in pythont t prime number in pythoncheck prime in pythoncheck whether a number is prime or not in pythonhow to test to see if a number is prime pythonhow to find prime numbers in python write a python function that takes a number as a parameter and checks if the number is prime or not python code for prime numbershow to check that give number is prime or not in pythonalgorithm to check prime numberpython program to check if number is prime or nothow to find if a number is prime or not in pythonprime number checker algorithm pythonisprime python accept a number and chck whether it is prime or composite pythonopython prime number codepython function to see if a number is primehow to check if a number is prime in pythonpython prime checkeris prime pythonwhether a number is prime or not in pythonhow to check whether a number is prime or not in pythonprime number questions in pythoncheck if a number is prime numbers python without for loopto find prime no in pythonpython3 test if number is primepython check prime functionpython test if a number is primeis prime function in pythonhow to write a program to find prime number with pythonpython code to check prime numberprime function in pythonhow to know if a number is prime or not in pythonfinding a prime number in pythonpython prime or notprime numbers 6k 2b1 and 6k 1 python programmhow to find out if a number is prime or composite in pythondeturmin if entered number is a prime number python codehow to check if any input is a prime number pythonhow to check if the input number is prime in pythonprime numbers in pythonfunciton to check prime in python python prime and even numbers in pythonwrite a program to check if a given number is prime or not pythonis a number a prime algorithmhow to find prime number pythonhow to find if element is prime or not in pythonknow if a number is prime pythonpython how to check if a number is primewrite a python function to check whether the number is prime or notprime not prime in python optimal solutioncheck if number is prime python quicklycheck if its a prime in pythonfind primes in pythonalgo python prime numberhow to find a number is a prime number in pythoncheck prime function pythonprimer number checker pythonhow to know if the number is a prime number pythonprime count program in pythonpython program to check prime no python program to find prime numbers or notfind if number is prime pythonhow to create a prime number tester in pythonpython prime check inbuiltwap to check whether the number is prime or not in pythonprime check algorithmpython programs to check prime numberis prime number in pythonwrite a python function that takes a number as a parameter and check the number is prime or notpython function checking a prime numberhow to check if number is prime in pythonhow to check for a prime number in pythondetermine if a number is prime pythonhow to determine if a number is prime pythonalgorithm to check if a number is primehow to find if number is prime pythoncheck prime number or not in pythonpython prime testprime number algorithm pythonpython function to check near prime numberfunction to find prime number in pythonalgorithm to find if a number is primehow do you check if a number is prime in pythonprime finder pythonprogram for prime number pythoncheck prime or not in pythonalgorithm to find prime numberhow to check a number is prime or not in pythonpython how to check prime numberhow to find out if your number is prime in pythoncode to determine if a number is primefunction to check prime number in pythontkinter prime numberprime number in python 27whether or not it is prime using pythonwrite a program in python to check if a number is prime python test for a prime numberfunction to check if number is prime pythonsimple program that determines if a number is prime pythonpython code to determines if x is prime or notfind the prime number in pythonhow to check the given number is prime or not in pythonwrite a program to check if number is prime or not in pythonprimality test pythontell if number is prime pythonhow to check for prime numberin pythoncheck even or prime number in pythonpython how to tell if a number is primegiven a positive integer n check whether the number is prime or not in pythonsee if number is prime pythonpython prime numberinput a number and check if the number is a prime or composite number in pythonpython progam for prime nopython find if a number is primeprogram to check whether a number is prime or not in pythonpython check if prime without importshow to check number is prime or not pythonhiw to check prime no in pythonprime numbers program in python gfgfastest way to check if number is prime pythonis prime pythonhow to get a prime number in pythoncheck whether a given number is prime or not in just one lineif prime pythontest if prime pythonprime num check pythonpython prime number functionwrite a program that will ask the user to enter 10 numbers separate the numbers in 2 parts 2c prime numbers and non prime nos in python python prime number is primeprime check in pythonhow do you find if a bnumber is prime pythonprogram in python to check whether a number is prime or notchecking for prime numbers in pythonhow to check if n is prime pythonfinding prime no in pythonhow to know if the number is prime in pythonpython function to check if a no is prime or notprime number check pythoncheck a prime number in pythonpython prime number programizpython3 is prime functionfunctuon to check if num is prime pythonprime number in python o 28n 29python function return prime numberpython function to check whether the number is prime or notpython check if the number is primepython method to check if primegiven a list of one digit numbers 2c print has primes if there are prime numbers in the list 2c and no primes if there are no primes python program to find prime numbers or composite numberpython code check if number is primetest if a number is prime pythonpython number is prime or nothow to find out whether a number is prime or not in pythoncheck if a number is prime python without for loopcheck if a nuber is prime fast pythonhow to see if number is prime in pythonpython check if number primepython prime number checkerprime number program in python 27program for prime number in pythonprogram to check prime number in pythonhow to tell an integer is prime pythonwrite a python program to check whether a number is prime or not python program to determine if a number is primecheck if a number is prime or not in pythonprime nummbers pythonpython how to find primes programme a method which determines whether a given number is a prime number 3f pythonhow to wirite an python code that given number is prime or notpython program to check whether a given number is prime or notfind prime number pythonhow to check if somethning is prime in pythonpython code for prime numberpython check for prime numberpython determine prime numberprime numbers code in pythonto check the number if it is prime or not in python in order of 1python program to find the given integer whether it is prime or not input from command promptcheck is prime pythonpython check if number is primefor a given number 2c check whether the number is a prime number or not in pythonfermat 27s primality test pythonwrite a function to check if a number is prime pythonhow to determine prime number in pythoncheck if prime number or not pythonmodule to check if number is prime pythonhow to check a prime number in pythoncheck if an given number is prime pythonbest way to find prime numbers pythonpython math primepython program to check if the input number is prime or notprime check package python 5dto check whether a number is prime or not in pythonpython check number is primecode to check if a number is prime pythoncheck if an given number is prime python without looptest cases for function to check number is prime pythonprime in pythoncheck a number is prime or not in pythoncheck whether scanned number is prime or not pythonpython how to check for prime numberspython is a number primeto check prime number in pythonwhether the number is prime or not in pythonfunction to check if it is a prime number pythonprime number detectord pythonpython library check if number is primeprime checker in pythoncheck if n is prime pythonhow to tell python if this is a prime numberfind preimenumber pythonprime numbers pythonpython program to check if a number is prime or notpython program to check if a number is primepython code for prime number or notcode to find primery numbersenter a number and check whether the number is prime or not in python 22check prime 22 pythonhow to find number is prime or not in pythonpython function to check in number is primehow to make a prime number checker in pythonask the user for a number and determine whether the number is prime or not python python check if value is primeis prime python functionpython check primesfinding prime numbers in pythoncheck if num is prime pythonhow to check if a number is a prime number and print it in pythoncheck for prime number in pythonprime nember in pythoncheck for prime numbers pythonprime no in pythonpython program to check prime numberpython primerpython is primepython code to check prime numnercheck the number is prime or not in pythoncheck if a number is prime python codeprime number test in python fermats primality test pythonpython prime number listcheck if a number is prime or no in pythonets write the function to do this and check the speed 21 is prime fast will take a number and return whether or not it is primecheck if number is prime in pythonwrite a program to check whether a number is prime or not in pythonpython check if number is prime numbercheck prime and even number in pythonhow to check prime number with loopprogramme a method which determines whether a given number is a prime number 3f pythonprime numbers algorithm in pythonpython determin if prime or notprogram to fing prime number in pythona program to check prime number in pythonhow to determine a prime number in pythonhow to determine if a number is prime in python in a loopprint if a number is prime or notis prime in pythonprime number or not in python in pythonprogram to check if number is prime in pythoncheck whether no is prime or not in pythonpython program to find if a number is prime python to check whether a number is prime or not how to determine prime number pythongiven a positive integer n check whether the number is prime or not in python determine prime number pythoneasy way to check for primes numbers python9 how would check a number is prime or not using python 3fpython problems like prime numberspython tell if number is primeprimre number in pythonhow to check if a given number is a prime number or not in pythonchecking if number is prime or odd in pythoncheck whether given number is prime or not in pythonhow to tell if a number is prime pythonprogram that figures out if a number is primequick python code prime checkpython check if number is prime code3 write a python function to check whether the number is prime or notprime number logic in pythonpython program to check number is prime or notpython if prime numberfunctions that find prime number pythonprime checking pythonpython check if its a primenumberpython prime checkfind out if a number is prime pythonpython find all prime numberscheck for prime pythonhow to tell if number is prime pythonsimple prime number program in pythonprime number checking login in pythonprime numbers program in python using functionwrite a program to find whether the given number is prime or not pythonprime no program in pythonhow to determine if a number is prime in pythonalgorithm to find prime numbersefficient prime check pythonchekc if a number is prime pythonalgorithm to check if number is primepython program to find number is prime or notto check the number if it is prime or not in pythoncheck prime number with tkinter entryfind a number is prime or not in pythonprogram to check if a number is prime in pythonpython prime number checkcheck whether prime or not in pythonprogram to check if number is prime or not pythoncheck primes pythonyour task is to write a function checking whether a number is prime or not how to check if prime number pythonhow to detect prime number in pythonpython function to check if a number is primehow to check prime number pythonpython prime number testhow to check if number is prime pythonprime number checker in pythonhow to calculate prime numbers pythonhow to figure out if a number is prime in pythonprime number in pythondetermine if prime pythoncheck prime number tkinter pythonpython program to check prime number or nothow to check whether a number is prime or not pythonprime no code in python python checking for prime numberswrite a program to check whether a number is prime or not in python with if elsecheck prime function in pythonhow to check if number is prime or not pythonwrite a program to find the given number is prime or not in pythoncheck a number is prime number or not in pythonprime number finding algorithmcheck number whether prime or not in pythonprime number condition pythoncheck if number prime pythonhow to get prime numbers in pythongiven number is prime or not in flaskprime number algorithm in python4 write a python program to check prime number 3fdefinig a function to chech if a number is prime in pythonpython is a number pri c3 b9epython code for determining prime numbers program in python to check if a number is prime python program to check if a number is prime or not using isprimehow to tell a number is prime pythonprime testing pythonprime number check in pythonpython in determining whether a number is primeinbuilt function to check prime number in pythoncode to check if a number is prime in pythonpython is number primehow to check if number is prime number pythonpython prime number checker functionfind if the number is prime in pythonhow to check prime in pythonprime test pythoncheck if the number is prime or not in pythonfind prime pythoncheck prime series in pythonsee if a number is prime pythonprimr number finding pythonprime number finder in pythoncheck number prime or not pythonchecking for a prime number in pythonpython check primehow to find if a number is prime number pythonprime function in pythopnwhether a no is prime or not in pythona functoin to check if a number is prime in pythonprimes check pythonhow to check if a number is a prime number in pythonpython code to see if numbers are primepython code to find if a number is prime or compositehow to identify a prime number in pythonpython program to check no given a positive integer n check whether the number is prime or not in python by taking input from userprime checker pythoncheck whether a number is prime or not without loop in pythonprime numbers using pythoncheck if prime pythonpython program to check primehow to check prime number in pythonpython check if prime or notpython code to check for prime numberso know whether the number is prime or not in pythontest for prime number pythonpython prime number 5cprime python 3how to test if a number is prime in pythonwrite a program that prompts the user to input a positive integer it should then output a message indicating whether the number is a prime number pythonpython program to find a number is prime or nothow to find if a number is prime in pythonprime or composite pythoncheck if a number is prime pythoncheck for prime number pythoncheck if a number is prime in pythonprime number in python without for elsefind number is prime or not pythonprime numbers formula pythonpython function to check if number is primesimple python logic to check for primespython checking if number is primepython program to check whether a number is prime or nothow to verify a prime number pythonhow to check prime numbers in pythonprime number python how to find if a number is the power of a prime pythonif prime number pythonprime numbers python isprimecheck number if it is prime pythonto check the number is prime or not in pythonpython program for prime numberpython check if int is primepython check if priem numberdetermining if a number is prime pythonprime no program in pythoncheck whether a number is prime or not pythonprimecheck pythonenter number to see if it is primewrite a python program to determine check it is prime number or not python chech number is prime or notis number prime pythonalgorithm for finding a prime numberhow to find if a number is prime in pyhtonprime numbers function pythonverify a prime number in pythoonpython algorithm for prime numberspython primepython check if a number is a prime nuimberhow to find whethe a number is prime or not in pythonpython fastest way of checking if number is primepython prime testercheck whether a number is prime or not if prime display it as prime if not prime find its prime divisorhow to check whether number is prime or not pythonprime no check in pythoncode for prime number in pythonpython program to find prime or notprime number test pythonpython check if primeprime number python codecheck prime pythonpython find if primeoptimus code in python to find the prime numberspython shell print number if it is prime numberhow to check if a number is a prime in pythonfind prime number in python using functionprime number function pythonprime number not using loop in pyprime or not python programpython find if number is divisible by prime numberpython is prime functionhow to check for prime number in pythonpython isprimepython determine n is primefind a prime number algorithmpython is prime numberfastest way to check prime number pythoncheck prime number program in pythonhow to find idf a numeb re si prime ornot in pythonpython trick to find if a number is prime or notpython program to check if the number is prime or notwrite a program to check if a given number is prime or not in pythonpython prime number programpython check if prime numverprime number in python using functionprogram in python for prime numbercompute if a number is prime pythonprogram that determines if a number is prime pythonhow to find a given number is prime or not in pythonprime number python programtest prime number python algorithm of functions of check prime numberhow to check if something is a prime number pythonhow to know if a number is prime pythontest prime number pythonnumber is prime or not in pythonprime number program in pythonhow to check prime using function in pythona number is prime or not in pythoncode to check prime number in pythonhow to tell if a number is prime in pythonchecking a number is prime or not in pythonprime or not in python using functionhow to determine if a number is prime using pythonchecking a prime number pythonhow to tell if a number is not prime in pythonwrite a fubction to check if a given number is prime or not in pythoncheck number is prime or not in pythonefficient prime number checking algorithmchecking if prime pythonhow to find if a numer is prime or not in pythoncheck for prime numbers in pythonwrite a code using a function to check whether a given number is prime number or not pythonpython check for primeprime number function in python 29 write a python program to check if a number is a prime numbercheck if number is prime pythonfunction to find whether a number is prime in pythonprime number checker pythoncheck if number is a prime pythoncheck prime number in python functioncheck if prime or not pythonprime numbers program in pythoncheck if a number is prime or not pythoncheck int is prime pythonhow to tell an integer is prime python with if statement pythonpython funciton to check if a no is prime or notto check a prime number in pythonfind prime numbers algorithmwrite a program to check whether a number is prime or not pythonpython priime number checkerchecking if a number is prime pythonfinding prime numbers in python starting with apython prime number program exampletest for a prime number pythonprime check pythonprime number formula pythoncheck for a prime number pythonpython function to check the prime numberfunction prime numbers pythonprime numbers check in pythonprime algorithm pythoncheck if the number is prime pythonaccept a number and check whether it is prime or composite python python program to check whether the given integer is a prime number or notchecking if number is prime pythonpython check if prime numbercheck prime tkinter pythonhow to see if a number is prime in pythonprogram to check prime number pythonpython number is primeprogram to find prime numbers in pythonprime pythonhow to check whether number is prime or not in pythonif a number is prime or not in pythonpython program to check whether a number is prime or nocheck if prime in pythonprime number library in pythonpython program for nested if statement to program on prime numberprime check function pythonpython 2 prime numberpython determine if primewrite a function in python that checks if a number is primewrite a python function that takes a number as a parameter and check the number is prime or not python check if a number is a primeif no of prime or not pythonhow to find if no is prime in pythongiven a positive integer n 2c write a program in python that checks if the number is prime or not write a program to check prime number in pythoncheck prime no in pythontake input from the user and find out if that number is prime or not is prime number pythoncheck if number is prime with math module pythonpython if is primefind if a number is prime in pythonwap in python to check whether a number is prime or not prime number detector pythonhow to check if a number is prime in python