Printing primes

For our first programming assignment you will write a Python program that can print all of the prime numbers between 1 and 1000.

What to do

Start by making a list of the first few primes.

primes = [2,3,5,7]

Then, set up a loop that iterates over the range from 10 to 1000. For each number n in this range do the following:

  1. Iterate over all of the primes d in the primes list.
  2. For each d check to see if d divides evenly into n. If it does, make a note of this. (The test n % d == 0 will tell you whether or not d divides evenly into n.)
  3. If none of the primes divided evenly into n, append n to the list of primes.

After you have checked each n in the range, print the list of primes you have found.

How to turn in your work

Put all of your code into a .py source code file and email that file to me as an attachment.

Due date

This assignment is due by the start of class on Tuesday, Sept. 26