anonymous
  • anonymous
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)
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.

Get our expert's

answer on brainly

SEE EXPERT ANSWER

Get your free account and access expert answers to this
and thousands of other questions.

anonymous
  • anonymous
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)
jamiebookeater
  • jamiebookeater
I got my questions answered at brainly.com in under 10 minutes. Go to brainly.com now for free help!
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.

Get this expert

answer on brainly

SEE EXPERT ANSWER

Get your free account and access expert answers to this
and thousands of other questions

anonymous
  • anonymous
Oh, and if you care to comment on my code, that would be cool too.
anonymous
  • anonymous
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.
anonymous
  • anonymous
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.

Looking for something else?

Not the answer you are looking for? Search for more explanations.

More answers

anonymous
  • anonymous
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?
anonymous
  • anonymous
@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 prime_divisor=prime_divisor+1 you see that I add 1 to the prime divisor each time their is a remainder found
anonymous
  • anonymous
@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.
anonymous
  • anonymous
I have now adjusted my code, but I still get stuck in some sort of infinite loop...
anonymous
  • anonymous
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.
carlsmith
  • carlsmith
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.
carlsmith
  • carlsmith
The second uses the logic from the above script to create a little function, then uses that to find the 1000th prime.
carlsmith
  • carlsmith
Let me know if you're still stuck, I'd be happy to help.
anonymous
  • anonymous
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.

Looking for something else?

Not the answer you are looking for? Search for more explanations.