Prime numbers: introduction to Python
Background
We can introduce several useful features of the Python language and
associated libraries by writing a program to generate prime
numbers. We can also test mathematical predictions of the
asymptotic density of primes.
Learning Goals
Science: There are no real science goals for this simple
warmup exercise. If you're interested in the mathematics of prime numbers,
feel free to work through the material on the asymptotic density of primes.
Since this is really an exercise to get familiar with Python, however,
the PrimesHints.py file already implements much of that.
Computation:
As part of
Getting
Started with Python, this exercise will introduce you to modifying
Hints files, writing Python functions,
using the editor and the ipython interpreter, and simple
plotting commands.
Procedure
Consult the instructions in the section
"External editors, %run, and Hints files"
in the
Getting Started with Python page.
Files
Links
James P. Sethna,
Christopher R. Myers
Last modified: August 24, 2006
Statistical Mechanics: Entropy, Order Parameters, and Complexity,
now available at
Oxford University Press
(USA,
Europe).