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 :: import mean squared log error 
Python :: format to 2 or n decimal places python 
Python :: dotenv error pip python 
Python :: save plot python 
Python :: python get full path 
Python :: python reload import 
Python :: pickle a dictionary 
Python :: save clipboard data win32clipboard python 
Python :: plot keras model 
Python :: create python virtual environment 
Python :: split array into chunks python 
Python :: python readlines without n 
Python :: python gui programming using pyqt5 
Python :: python how to save a Seaborn plot into a file 
Python :: Presskeys in python 
Python :: Flask Gmail 
Python :: pandas add index 
Python :: DEPRECATION: The default format will switch to columns in the future. You can use --format=(legacy|columns) (or define a format=(legacy|columns) in your pip.conf under the [list] section) to disable this warning. 
Python :: reverse row order pandas 
Python :: pandas convert all column names to lowercase 
Python :: pandas append csv files a+ 
Python :: rmse in python 
Python :: tf 1 compatible colab 
Python :: send message to specific channel discord.py 
Python :: python3 iterate through indexes 
Python :: pandas insert column in the beginning 
Python :: python virtual environment 
Python :: python random number 
Python :: clibboard to png 
Python :: print image python 
ADD CONTENT
Topic
Content
Source link
Name
3+9 =