Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

Python code for checking if a number is a prime number

for i in range(2, 20):
    for x in range(2, i):
        if i % x == 0:
            break
    else:
        print(i, "is a prime number")
Comment

how to see if a number is prime in python

def is_prime(n: int) -> bool:
    """Primality test using 6k+-1 optimization."""
    if n <= 3:
        return n > 1
    if n % 2 == 0 or n % 3 == 0:
        return False
    i = 5
    while i ** 2 <= n:
        if n % i == 0 or n % (i + 2) == 0:
            return False
        i += 6
    return True
Comment

check if number is prime python

def check_if_prime():
    number = int(input("Enter number: "))
    
    prime_lists = [1,2,3]
    
    divisible_by = []
    if number in prime_lists:
        return divisible_by
    
    if number==0:
        return None
    
    for i in range(2,number):
        
        if number%i==0:
            divisible_by.append(i)
            
    return divisible_by
        
    
check_if_prime()
Comment

PREVIOUS NEXT
Code Example
Python :: how to make a button in python turtle 
Python :: [0] * 10 python 
Python :: How are iloc and loc different? 
Python :: how to know the python pip module version 
Python :: python pyqt5 
Python :: pass keyword python 
Python :: how to set variable in flask 
Python :: max pooling in cnn 
Python :: how to code python 
Python :: webscrapping with python 
Python :: oython 
Python :: matplotlib vertical line 
Python :: how to open ndjson file in python 
Python :: how to use function in python 
Python :: print flush python 
Python :: strp datetime 
Python :: python for character in string 
Python :: is python oop 
Python :: matplotlib bar chart 
Python :: python initialize dict with empty list values 
Python :: pyqt5 image center 
Python :: print font size python 
Python :: django query multiple conditions 
Python :: tkinter entry focus 
Python :: bs4 class 
Python :: python plot two lines with different y axis 
Python :: string remove in python 
Python :: legend matplotlib 
Python :: count proportion pandas 
Python :: Aligning rotated xticklabels with their respective xticks 
ADD CONTENT
Topic
Content
Source link
Name
4+3 =