anonymous
  • anonymous
Finally problem 1 finished!! # Finding up to the 1000th prime x = 0 count = 0 div = [] primes = [] while count <= 1000: if x > 1 and not(x%2) == 0: for i in range(1, 1+x): if x%i == 0: div += [i] if div[1] == x: primes += [x] count += 1 x += 1 del div[:] However, I don't know how to account for 2.. Also, please critique the code. Thanks
MIT 6.00 Intro Computer Science (OCW)
chestercat
  • chestercat
I got my questions answered at brainly.com in under 10 minutes. Go to brainly.com now for free help!
At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.

Get this expert

answer on brainly

SEE EXPERT ANSWER

Get your free account and access expert answers to this
and thousands of other questions

anonymous
  • anonymous
just add 2 to primes before you loop. If you're taking advantage of the fact that primes aren't even you're using some apriori knowledge of the problem, and doing so also implies that 2 is a prime.
anonymous
  • anonymous
other things, try to avoid using variables like i, and x. Instead name them things that make sense i is a possibleDivsor, x is a possiblePrime. Also div = [] is a bit nicer than del div[:] in terms of expressing what you mean. Just move the initialization of div into your while loop at the top and you won't have to delete it at the bottom of the loop.
anonymous
  • anonymous
Cool, thanks polak

Looking for something else?

Not the answer you are looking for? Search for more explanations.