Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

find a prime number in python

def prime_checker(number):
    is_prime = True #use a bool to flag prime number
    for i in range(2, number):# starts at 2 and loops until the range of number
        if number % i == 0:# if is divisible not a prime
            is_prime = False
    if is_prime == True:
        print(f"{number} is a prime number")
    else:
        print(f"{number} is a not a prime number.")

n = int(input("Check this number: "))#check a number for prime
prime_checker(number=n)#call the function
Source by repl.it #
 
PREVIOUS NEXT
Tagged: #find #prime #number #python
ADD COMMENT
Topic
Name
8+2 =