WellsPrimes.zip is a collection of around 200 short Python programs that I've put together to illustrate most of the topics covered by David Wells' book Prime Numbers: The Most Mysterious Figures in Math. His text is an excellent introduction to prime numbers, organized as a comprehensive A-Z guide, which manages to explain the basic maths without overwhelming the novice. A simple way to get a taste for the material is to browse the contents pages, which I've linked to here as a short PDF.
A typical example of one of my programs is differs.py. Its documentation includes links to the relevant section in Wells, Wikipedia, Mathworld, PrimesPages or OEIS, and some information on how to run the code.
Around 60 of my examples generate images (mostly graphs) using third party libraries (mostly matplotlib). Click on any of the following links to see some output examples:
matplotlib images: benford.py, bias.py, brocard.py, brun.py, consecShare.py, coprimePlot.py, coprimeScatter.py, densityPrimes.py, differs.py, digitalRoots.py, divisorsPlot.py, divisorsSumPlot.py, ellipticPlot.py, eulerRecip.py, eulerTotNNPlot.py, gammaL.py, gapsBar.py, gaussCircle.py, gaussianPrimes.py, gaussianSpiral.py, goldbachComet.py, HardyL2.py, liPlot.py, littlewoodDiff.py, mersenne.py, mertensConst.py, primeGraph.py, riemannZeta.py, riemannZeta2.py, riemannZeta3.py, spiral.py, spiralUlam.py
graphviz images: drawPrimeSums.py, modmult.py
pygame images: eratoVisual.py
turtle images: spiralSacks.py
My examples rely on a small set of prime utility functions in pUtils.py. It relies on two other libraries: Jared Suttles' pyprimesieve and a 'backup' module called pyprimes.py (coded by me, and in the zip file).
pyprimesieve can be installed with pip (e.g. with pip install pyprimesieve), which will bring with it the C/C++ primesieve library developed by Kim Walisch. This offers incredibly fast prime sieving, checking, and factorization, but requires the C code to be compiled. pip will call an installation script which should work without a problem. However, on one of my old MS Windows test machines, the installation crashed when it could not find Microsoft Visual C++ 14.0. The solution is to download Microsoft C++ Build Tools. You only need to install the "Desktop development with C++ tools" subset (a mere 7 GB). A new call to pip will now compile primesieve as pyprimesieve is installed.
The primary reason for my having a pyprimes.py 'backup' module is not the difficulty of installing the C library, but to deal with its inherent limitation to 64-bit integers. Primes can easily get bigger than this, which will cause pyprimesieve to raise an Overflow exception. My functions in pUtils.py catch this exception (by default silently, but you can override that), and pass the offending integer to the equivalent function in my pyprimes.py backup. Since Python can deal with unlimited size integers, the code in pyprimes.py will execute happily. However, this doesn't always 'solve' the problem since the sheer size of the numbers may mean that the code will take 'forever' to generate an answer. One fix I've used in pUtils.py is to use the Overflow of a call to isPrime() to trigger a switch to a probabilistic checker function, isPrimeMR().
Wells' book doesn't have much information on how prime numbers relate to the rest of number theory. For a beginner I recommend A Friendly Introduction to Number Theory by Joseph H. Silverman. For people who prefer video introductions, I recommend the Youtube playlist Introduction to Number Theory (Berkeley Math 115) by Richard E. Borcherds.