I keep entering the following code into the IDLE: http://pastebin.com/nzG9Nva7
by copy and pasting, and it returns nothing. Is there a special way to compile your code?
BTW: this is problem set 1 question 1, computing the 1000th prime
MIT 6.00 Intro Computer Science (OCW)
Stacey Warren - Expert brainly.com
Hey! We 've verified this expert answer for you, click below to unlock the details :)
At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga.
Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus.
Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.
I got my questions answered at brainly.com in under 10 minutes. Go to brainly.com now for free help!
Oh, and if you care to comment on my code, that would be cool too.
save your code in a new window as a .py file then click run tab and run module. after that call your code from idle.
I was wondering, does your code find primes or even and odd? you have to use more divisors than just 2 to determine if it is prime.
Not the answer you are looking for? Search for more explanations.
I think the biggest issue with this code is some confusion between the variables prime_counter and prime_candidate. Can you explain what you intend for these two pieces of data to represent?
@jpkita yes, my code is designed to find primes. however, now that I'm using your advice and running it, it only returns 3, 5, and then doesn't return anything. If you look at this peice of code: if prime_counter%prime_divisor>0:
###checking to see if there is a remainder
you see that I add 1 to the prime divisor each time their is a remainder found
@polpak prime_counter is just keeping track of which prime number I'm on. Prime _candidate is the number being checked for prime-ness. There is currently an issue with my code, and I'm addressing it.
I have now adjusted my code, but I still get stuck in some sort of infinite loop...
well - version two seems to have some confusion with prime_counter and prime_candidate as mentioned earlier - what are you using those variables for? Maybe pick a place in the code and print their values to see what they are doing.
Here are two example scripts, they are full of explanatory comments and you don't need to download them, they open in a new tab.
The first finds whether a number is prime or not.
Let me know if you're still stuck, I'd be happy to help.
Hi carl, thanks for the help. I kind of wanted to get these answers without blatantly looking at someone else's code, but thanks for the help. I was able to create a script to determine whether a question is prime or not, but could not accurately determine the 1000th prime (I was off by two). Here's my code: (V3.0) http://pastebin.com/nzG9Nva7 Oh, and I created a new post because this one is a bit bogged down.