Hey I'm working on PS1 and I was just wondering what I did wrong http://dpaste.com/568800/ when i run it the output is 2003.. which is not the 1000th prime.
Actually, it's because you simply prints the 1000th odd number after 3. x = 2n + 1, with n starting from 1 to 9999, would yield odds, and exempt even numbers. And therefore, if x % 2 != 0 is pretty much useless. All of your numbers were odds already, so of course they can't be divided by 2.
http://dpaste.com/568815/ I was able to define prime and print the info. now can someone help me how to make it stop at the 1000th.
Oh and when comment out the "##print n, 'equals', x, '*', n/x ##print if any" it will only show prime number between 1-9999.
Wait, what about your earlier tuple method?
I couldnt set a solid definition of 'prime' so i decided to go with another method.
Here's a hint: There whould be two loops in there. One for the prime candidates, and the other for the divisors.
Who would you set the loop for the divisors? for the prime candidates i got x = 3 y = 2 while x > y: if x % y == 0: x = x + 2 y = 2 else: ... ## loop for divisors go here i guess
I wouldn't divide it with 2. It'll always be false, since your candidates are all odd numbers.
In theory this should work but I think im sending it into an infinite loop... http://dpaste.com/568850/
in line 2 your limit is 9999 so it is not infinite.
http://dpaste.com/hold/568878/ Like I said, doing it without tuples/lists is a royal pain in the rearside....
Join our real-time social learning platform and learn together with your friends!