A community for students.

Here's the question you clicked on:

55 members online
  • 0 replying
  • 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

  • This Question is Closed
  1. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    Oh, and if you care to comment on my code, that would be cool too.

  2. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    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.

  3. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    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.

  4. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    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?

  5. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 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

  6. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    @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.

  7. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    I have now adjusted my code, but I still get stuck in some sort of infinite loop...

  8. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    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.

  9. carlsmith
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    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.

  10. carlsmith
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    The second uses the logic from the above script to create a little function, then uses that to find the 1000th prime.

  11. carlsmith
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    Let me know if you're still stuck, I'd be happy to help.

  12. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    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.

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

    • Attachments:

Ask your own question

Sign Up
Find more explanations on OpenStudy
Privacy Policy

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

This is the testimonial you wrote.
You haven't written a testimonial for Owlfred.