A community for students.
Here's the question you clicked on:
 0 viewing
anonymous
 5 years ago
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
anonymous
 5 years ago
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

This Question is Closed

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0Oh, and if you care to comment on my code, that would be cool too.

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0save 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
 5 years ago
Best ResponseYou've already chosen the best response.0I 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.

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0I 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
 5 years ago
Best ResponseYou've already chosen the best response.0@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
 5 years ago
Best ResponseYou've already chosen the best response.0@polpak prime_counter is just keeping track of which prime number I'm on. Prime _candidate is the number being checked for primeness. There is currently an issue with my code, and I'm addressing it.

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0I have now adjusted my code, but I still get stuck in some sort of infinite loop...

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0well  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
 5 years ago
Best ResponseYou've already chosen the best response.0Here 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
 5 years ago
Best ResponseYou've already chosen the best response.0The second uses the logic from the above script to create a little function, then uses that to find the 1000th prime.

carlsmith
 5 years ago
Best ResponseYou've already chosen the best response.0Let me know if you're still stuck, I'd be happy to help.

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0Hi 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.
Ask your own question
Sign UpFind more explanations on OpenStudy
Your question is ready. Sign up for free to start getting answers.
spraguer
(Moderator)
5
→ View Detailed Profile
is replying to Can someone tell me what button the professor is hitting...
23
 Teamwork 19 Teammate
 Problem Solving 19 Hero
 Engagement 19 Mad Hatter
 You have blocked this person.
 ✔ You're a fan Checking fan status...
Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.