Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from math import*
- c=1
- x=3
- p=2
- n=20 #I changed this to a smaller number. Increase it as you work out some of the bugs!
- logsum=log(2)
- while x<n: #I think you want c<n here because you want to find the 1000th prime right?
- prime=True
- #divisor=3
- #while divisor<(x/2):
- #Maybe combine these last two statements into a 'for' statement. Along these lines:
- for divisor in range(3, x/2): #basically the same idea but more concise...
- ###This next section is where you are running into trouble. I would suggest
- ###simplifying these tests...
- if x%divisor>0:
- divisor=divisor+2
- else:
- prime=False
- divisor=x
- if prime==True:
- c=c+1
- p=x
- logsum=logsum+log(p)
- x=x+2 #Indent was wrong here, moved it left so you aren't stuck in an infinite loop.
- #I added these print statements so you can maybe see how it is running off track in
- #your first if statement. The p values are not the correct prime numbers,
- #and c is not right either. See if you can fix it...it isn't very far off.
- print 'x=',x
- print 'p=',p
- print 'c=',c
- print logsum
- print n
Advertisement
Add Comment
Please, Sign In to add comment