Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

is prime python

def is_prime(n):
    for i in range(2,int(n**0.5)+1):
        if n%i==0:
            return False
    return True
Comment

is prime python

import math
def isPrimeNumber(n):
    if (n < 2):
        return False;
    sq = int(math.sqrt(n))
    for i in range(2, sq + 1):
        if (n % i == 0):
            return False
    return True
Comment

primes in python

from math import sqrt
for i in range(2, int(sqrt(num)) + 1):
    if num % i == 0:
        print("Not Prime")
        break
    print("Prime")

# Note: Use this if your num is big (ex. 10000 or bigger) for efficiency
# The result is still the same if the num is smaller
Comment

primes pytyhon

def is_prime(n):
    if n in (2, 3):
        return True
    if n <= 1 or not (n%6==1 or n%6==5):
        return False
    a, b= 5, 2
    while a <= n**0.5:
        if not n%a:
            return False
        a, b = a+b, 6-b
    return True
# this method is much faster than checking every number because it uses the fact
# that every prime is either 1 above or 1 below a multiple of 6
# and that if a number has no prime factors, it has no factors at all
Comment

python primes

def is_prime(n):
  for i in range(2,n):
    if (n%i) == 0:
      return False
  return True
Comment

primes python

import math

def main():
    count = 3
    
    while True:
        isprime = True
        
        for x in range(2, int(math.sqrt(count) + 1)):
            if count % x == 0: 
                isprime = False
                break
        
        if isprime:
            print count
        
        count += 1
Comment

is prime python

def is_prime(n):
  return bool(n&1)
Comment

PREVIOUS NEXT
Code Example
Python :: scrapy user agent 
Python :: python boxplot show mean 
Python :: pandas groupby count occurrences 
Python :: how do i create a file in specific folder in python 
Python :: timed loop python 
Python :: read csv without index 
Python :: python inspect source code 
Python :: python datetime to timestamp 
Python :: cprofile usage python 
Python :: python dividing strings by amount of letters 
Python :: python format decimal 
Python :: count how many times a value shows in python list 
Python :: python fizzbuzz 
Python :: how to test wifi speed py 
Python :: pandas filter on range of values 
Python :: find angle mbc in python 
Python :: Incorrect number of bindings supplied. The current statement uses 1, and there are 3 supplied. 
Python :: python drop axis 
Python :: how to draw shape square in python turtle 
Python :: remove spaces from a list python 
Python :: round python 
Python :: creat and active python environment 
Python :: get classification report sklearn 
Python :: pandas read google sheet 
Python :: python input integer 
Python :: python count hex 
Python :: fuzzy lookup in python 
Python :: python open file relative to module 
Python :: How to set font size of Entry in Tkinter 
Python :: how shorten with enter long script python 
ADD CONTENT
Topic
Content
Source link
Name
1+2 =