Guest User

Untitled

a guest
Mar 4th, 2012
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. from math import*
  2. c=1
  3. x=3
  4. p=2
  5.  
  6. n=20 #I changed this to a smaller number. Increase it as you work out some of the bugs!
  7.  
  8. logsum=log(2)
  9.  
  10. while x<n: #I think you want c<n here because you want to find the 1000th prime right?
  11. prime=True
  12. #divisor=3
  13. #while divisor<(x/2):
  14. #Maybe combine these last two statements into a 'for' statement. Along these lines:
  15. for divisor in range(3, x/2): #basically the same idea but more concise...
  16.  
  17. ###This next section is where you are running into trouble. I would suggest
  18. ###simplifying these tests...
  19. if x%divisor>0:
  20. divisor=divisor+2
  21. else:
  22. prime=False
  23. divisor=x
  24.  
  25. if prime==True:
  26. c=c+1
  27. p=x
  28. logsum=logsum+log(p)
  29. x=x+2 #Indent was wrong here, moved it left so you aren't stuck in an infinite loop.
  30.  
  31. #I added these print statements so you can maybe see how it is running off track in
  32. #your first if statement. The p values are not the correct prime numbers,
  33. #and c is not right either. See if you can fix it...it isn't very far off.
  34. print 'x=',x
  35. print 'p=',p
  36. print 'c=',c
  37.  
  38. print logsum
  39. print n
Advertisement
Add Comment
Please, Sign In to add comment