I've been working on ps1 part a. Here is my code http://dpaste.com/604895/ Python crunches the code forever without printing anything. I know the problem is where I increase "candidate" by 2. Any help fixing this will be much appreciated!
a couple of things: 1) make sure that your 'possible' variable is changing with each new prime number. 2) your conditional "if number % divisor !=0:" should read "if candidate % divisor..." 3) you are moving on to the next candidate after it passes the first test: "if candidate % divisor != 0" Make sure you don't increment candidate until you have determined whether or not it is a prime AND you have added to the counter. 4) the if statement at line 15 is redundant, because of the nature of the for loop, if it has passed all of the divisors' tests and the divisor reaches candidate/2, then you know it's a prime number. Hope that helps point you in the right direction.
That helped me a lot. After reading your comments and playing around with the code for a while I got it. Thank you!
a real good debugging method is to put print statements in where you think things might be going wrong and print things like variable values, indices, calc results, counters .... it will let you see what is happening to see if that is what you intended.
Join our real-time social learning platform and learn together with your friends!