Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python - prime number generator

# Prime number generator
def prime_generator(end):
    for n in range(2, end):     # n starts from 2 to end
        for x in range(2, n):   # check if x can be divided by n
            if n % x == 0:      # if true then n is not prime
                break
        else:                   # if x is found after exhausting all values of x
            yield n             # generate the prime


g = prime_generator(1000)       # give firt 1000 prime numbers
print(list(g)) 
Comment

generate random prime number python

import sympy

primeNumber = sympy.randprime(min, max)
Comment

prime number generator python

#prime number gen

nums=[]
max=10000

class N:
    def crazy():
        for i in range(max):
            nums.append(True)
        nums[0]=False
        nums[1]=False

        for index in range(max):
            if nums[index]:
                current_multiple = 2
                while index*current_multiple < max:
                    nums[index*current_multiple ]= False
                    current_multiple += 1

        for index in range(max):
            if nums[index]:
                print(f"----> {index} is a prime #")

N.crazy()
Comment

PREVIOUS NEXT
Code Example
Python :: ImportError: No module named _tkinter, please install the python-tk package 
Python :: numpy distance between two points 
Python :: python date now plus days 
Python :: bs4 find element by id 
Python :: rename one dataframe column python 
Python :: how to subtract minutes from time in python 
Python :: python catch all exceptions 
Python :: grouping products for sales 
Python :: a function to create a null correlation heatmap in python 
Python :: what is the tracing output of the code below x=10 y=50 if(x**2 100 and y <100): print(x,y) 
Python :: python selenium button is not clickable at point 
Python :: matplotlib multiple plots with different size 
Python :: kivy date widget 
Python :: pathlib get list of files 
Python :: python extract mails from string 
Python :: confusion matrix python 
Python :: Running setup.py bdist_wheel for opencv-python: still running... 
Python :: how to get input from user in python 
Python :: python default dictonary 
Python :: check cuda available tensorflow 
Python :: flip specific bit python 
Python :: ROLL D6 
Python :: how to save the history of keras model 
Python :: Python Split list into chunks using List Comprehension 
Python :: python pdf merger 
Python :: Python program to check leap year or not? 
Python :: append one column pandas dataframe 
Python :: unique words from pandas 
Python :: tkinter text in canvas 
Python :: install chromedriver ubuntu python 
ADD CONTENT
Topic
Content
Source link
Name
5+8 =