Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python prime check

def isPrime(n):
  if n<2:		#1, 0 and all negative numbers are not prime
    return False
  elif n==2:	#2 is prime but cannot be calculated with the formula below becuase of the range function
    return True
  else:
    for i in range(2, n):
      if (n % i) == 0:	#if you can precisely divide a number by another number, it is not prime
        return False
    return True			#if the progam dont return False and arrives here, it means it has checked all the numebrs smaller than n and nono of them divides n. So n is prime
Comment

check for prime in python

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

PREVIOUS NEXT
Code Example
Python :: drop column dataframe 
Python :: pandas get date from datetime 
Python :: max of matrix numpy 
Python :: mad python 
Python :: Tkinter canvas draggable 
Python :: how to create a loop in python turtle 
Python :: get classification report sklearn 
Python :: user nextcord interactions 
Python :: dataframe row 
Python :: convert mb to gb python 
Python :: python pip install 
Python :: draw a circle in python turtle 
Python :: python cv2.Canny() 
Python :: install qt designer python ubuntu 
Python :: get os information python 
Python :: tkinter hello world 
Python :: program to tell if a number is a perfect square 
Python :: Delete the node at a given position 2 in a linked list and return a reference to the head node. The head is at position 0. The list may be empty after you delete the node. In that case, return a null value. 
Python :: extract filename from path in python 
Python :: how to click on button using python 
Python :: scrfoll with selenium python 
Python :: get all h1 beautifulsoup 
Python :: update print python 
Python :: how to import pygame 
Python :: python export multiple dataframes to excel 
Python :: screen size python 
Python :: python loop x times 
Python :: python mysqldb 
Python :: How to install XGBoost package in python using conda 
Python :: python get path of current file 
ADD CONTENT
Topic
Content
Source link
Name
9+5 =