I tried to create a list of prime numbers with python

I created a program that displays a list of prime numbers using python.

A program that displays a list of prime numbers in python

main.py


def primeNumberCreate():
    primeList = [2]  #Create a list of prime numbers less than or equal to 2
    maxNumber = 1000 #Check numbers below 1000
    for x in range(3, maxNumber):
        for y in primeList:
            if x % y == 0:
                break
        else:
            primeList.append(x)  #Add to list if nothing is divisible
    return primeList

def indentAdjustment(primeNumbers): #For indentation adjustment
    count = 0
    for num in primeNumbers:
        print(f"{num:4}", end=" ")
        count += 1
        if count > 9:
            print(' ')
            count = 0

if __name__ == '__main__':
    primeNumbers = primeNumberCreate()
    indentAdjustment(primeNumbers)

The else processing of the for statement is executed after all the processing in the for statement is completed. What was not caught in the if statement is assigned to list. indentAdjustment () was created to adjust the indent.

The execution result is as follows.

terminal


   2    3    5    7   11   13   17   19   23   29  
  31   37   41   43   47   53   59   61   67   71  
  73   79   83   89   97  101  103  107  109  113  
 127  131  137  139  149  151  157  163  167  173  
 179  181  191  193  197  199  211  223  227  229  
 233  239  241  251  257  263  269  271  277  281  
 283  293  307  311  313  317  331  337  347  349  
 353  359  367  373  379  383  389  397  401  409  
 419  421  431  433  439  443  449  457  461  463  
 467  479  487  491  499  503  509  521  523  541  
 547  557  563  569  571  577  587  593  599  601  
 607  613  617  619  631  641  643  647  653  659  
 661  673  677  683  691  701  709  719  727  733  
 739  743  751  757  761  769  773  787  797  809  
 811  821  823  827  829  839  853  857  859  863  
 877  881  883  887  907  911  919  929  937  941  
 947  953  967  971  977  983  991  997 

Recommended Posts

I tried to create a list of prime numbers with python
I tried to create a program to convert hexadecimal numbers to decimal numbers with python
[Python] I tried to automatically create a daily report of YWT with Outlook mail
[Outlook] I tried to automatically create a daily report email with Python
I tried to create a table only with Django
I tried to draw a route map with Python
I tried to automatically generate a password with Python3
I tried to make a simple mail sending application with tkinter of Python
When I tried to create a virtual environment with Python, it didn't work
I tried to easily create a fully automatic attendance system with Selenium + Python
I tried to create a model with the sample of Amazon SageMaker Autopilot
I tried to automatically create a report with Markov chain
Mayungo's Python Learning Episode 3: I tried to print numbers with print
I tried a stochastic simulation of a bingo game with Python
I tried scraping food recall information with Python to create a pandas data frame
I tried to create a linebot (preparation)
I tried a functional language with Python
I tried to make a regular expression of "time" using Python
[3rd] I tried to make a certain authenticator-like tool with python
[Python] A memo that I tried to get started with asyncio
I tried to make a regular expression of "date" using Python
I tried to fix "I tried stochastic simulation of bingo game with Python"
I tried to make a periodical process with Selenium and Python
I tried to get a list of AMI Names using Boto3
I tried to make a 2channel post notification application with Python
I tried to create Bulls and Cows with a shell program
I tried to make a todo application using bottle with python
[4th] I tried to make a certain authenticator-like tool with python
[1st] I tried to make a certain authenticator-like tool with python
I tried to improve the efficiency of daily work with Python
I tried to automatically collect images of Kanna Hashimoto with Python! !!
I tried to make a mechanism of exclusive control with Go
I tried to create a Python script to get the value of a cell in Microsoft Excel
I wrote a doctest in "I tried to simulate the probability of a bingo game with Python"
[Python / DynamoDB / boto3] List of operations I tried
[Python] List Comprehension Various ways to create a list
I tried hundreds of millions of SQLite with python
[python] Create a list of various character types
I want to create a window in Python
I want to make a game with Python
I tried to get CloudWatch data with Python
I tried to output LLVM IR with Python
Steps to create a Twitter bot with python
I tried to automate sushi making with python
I want to write to a file with Python
Python: I tried to make a flat / flat_map just right with a generator
I tried to communicate with a remote server by Socket communication with Python.
I tried to create a plug-in with HULFT IoT Edge Streaming [Development] (2/3)
[Introduction to Python] How to sort the contents of a list efficiently with list sort
A function that generates a list with up to 3 prime numbers as elements
I tried to get the authentication code of Qiita API with Python.
I tried to make a traffic light-like with Raspberry Pi 4 (Python edition)
I tried to create a plug-in with HULFT IoT Edge Streaming [Execution] (3/3)
I tried to discriminate a 6-digit number with a number discrimination application made with python
A beginner of machine learning tried to predict Arima Kinen with python
I tried to streamline the standard role of new employees with Python
I tried to get the movie information of TMDb API with Python
I tried to create a plug-in with HULFT IoT Edge Streaming [Setup] (1/3)
I tried to build a Mac Python development environment with pythonz + direnv
I tried to create a sample to access Salesforce using Python and Bottle
I tried to implement a card game of playing cards in Python