0

I've started the MIT open course for beginners (its in Python) and the first assignment is: Write a program that computes and prints the 1000th prime number.

I have started to do it on my own with the things learned in the lectures, but after a few attempts at nested loops, I can't seem to produce any working code. Can I have any tips, have my errors pointed out?

divisor = 1
result = 2
odds = 1
total = 1

# all odd int generation

for x in range(100):
    total = total + 1

# test for each generated number

    for n in range(1, total / 2):
        if (result % divisor != 0):
            print "result: ", result, " is prime!"
    odds = odds + 2
    result = odds

It is incomplete, but even this part doesn't work for me.

KurzedMetal
  • 12,540
  • 6
  • 39
  • 65
Stabbz
  • 768
  • 5
  • 12
  • You don't do anything with `divisor` or `result`, so they are always 1 and 2 respectively. Did you mean to use `x % n` in the if statement? – Daniel Roseman Mar 17 '14 at 11:30
  • you are right, i've missed a bunch of stuff, ill review it myself a few more times and ask again if i get stumped, thanks! – Stabbz Mar 17 '14 at 11:33
  • Try to follow [Python Enhancement Proposal 8 aka PEP8](http://legacy.python.org/dev/peps/pep-0008/) when writing Python code. It's a convention designed for the standard library but pretty much the whole community use it. (In your case you are not using the proper whitespaces between operators and comas) – KurzedMetal Mar 17 '14 at 11:43
  • Thanks, I'll go trought that now. – Stabbz Mar 17 '14 at 11:49

0 Answers0