A community for students.

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

anonymous

  • 5 years ago

PSet 1, problem 1, the prime numbers thing. I'd just like to see if I'm on the right track. Here's what I have so far: testnum = 2 divisor = 3 goal = 2 ctr = 0 while ctr < goal: while divisor < testnum: if testnum%divisor == 0: ctr += 1 else: testnum +=1 while goal < ctr: print testnum I've been stalking the group all morning and somnamniac's replies to some other questions have helped a lot. Thanks in advance.

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

    First, you're not changing divisor anywhere, so it's never going to be greater than testnum. Second, ctr seems like the variable you're using to count primes, so why are you iterating it when there isn't any remainder?

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

    sorry, I meant incrementing there, not iterating.

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

    More generally, the answer to 'am I on the right track' usually depends on what the overall plan is, and to me the most important thing to learn is how to construct that plan. What's your plan for this problem?

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

    I did not mean to sound as arrogant as I did. I apologize for that. First + second: right, right, thank you. I'm fixing those. The plan for this problem was to check if the test number was prime or not, although I doubt it would even be able to do that the way I've written it. I'm honestly thinking I'm not meant to do coding/Python/computation. I just can't wrap my head around things, how to even go about coding a program for example. Thanks so much for your help/replies. I appreciate it greatly.

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

    Sorry, I didn't mean to suggest you sounded arrogant. I just meant to say that 'the plan' is the first thing to think about before you start getting lost in details, and that if you find yourself lost in details, it's time to revisit the plan. Don't give up!

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

    Oh, no you didn't, I just reread it and realized I sounded arrogant. :) That's true. I'll try that. Thanks!

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

    This is a great problem to start with in terms of learning to debug. If you try to just write it all the way through, if it doesn't work it can be hard to know what's wrong. I'd suggest trying to write a program that just takes one number and returns true if the number is prime and false if it isn't. That way it's easier to keep everything that should be happening in your head at once. And from my extremely limited experience, that's the trick--just knowing "if I had a way do this once, doing it a lot of times would be simple."

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

    I'll try that. Thank you so much.

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

    One thing that has helped me a lot with this problem set is writing down, on paper, a flowchart of what you want the program to do, in every little step. If you write your algorigthm down it's much easier to wrap your head around all the moving parts, especially if like me this is the first time you've ever done something like this.

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