hi, im trying to solve the problem of finding the 1000th prime, and have written this code: x=2 n=0 i = range (2,9999,1) while (n<=1000): if x%i == 0 and x == i: print i x=x+1 n=n+1 can someone plz tell me why this is not working? (i am all new to programming) :)
what is not working?
a few things to note, 1) use Dpaste.com, it works better 2) range has optional arguments, if your say range(2,9999) it'll work just fine, most of the time i just do something like range(10) if i just want a quick test run of 10 3) range produces a list with the endpoints (x,y-1), your variable i = [2,3,4,5,6,...9998] you want a for loop for something like that for i in range(2,10000): x % i == 0 i don't suggest using a for loop here otherwise if you don't know if elif else are useful, many people miss the elif hopefully thats enough for now
try these resources: http://wiki.python.org/moin/BeginnersGuide http://wiki.python.org/moin/BeginnersGuide/NonProgrammers
I'm also new at programming, and trying to work through this problem. This question will probably sound dumb, but I was confused as to how n = 0 but at the same time n <=1000. If n =0 , wouldn't that make it definite?
n <= 1000 is an expression that evaluates to either True or False so if n = 0 then n <= 1000 is True
Join our real-time social learning platform and learn together with your friends!