Interesting how completely different mine is from elz's, even for a program this small:
#!/usr/bin/env python
# ps1a.py
# MIT problem set 1a, by me
# start with some helpful variabubbles
# note that we're starting with the first prime preloaded; this is admittedly kludgetastic
counter = 0
number = 2
while counter < 1000:
for i in range(2,number):
if number % i == 0:
break
# if there were no factors, print the prime and count it
else:
counter +=1
print counter, ": ", number, 'is prime'
number += 1
And for problem 2:
#!/usr/bin/env python
# ps1b.py
# MIT problem set 1b, by me
from math import *
max = input("enter a number: ")
sum = 0
number = 2
# we're going to work through a whole range of numbers...
while number <= max:
# test each to see if it's prime
for j in range(2,number):
if number % j == 0:
break
else:
print number, "is prime: "
sum += log(number)
number +=1
# spit stuff out
print "sum of logs: ", sum
print "n = ", max
print "ratio: ", sum/max
no subject
And for problem 2: