A community for students.
Here's the question you clicked on:
 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.
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

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

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0sorry, I meant incrementing there, not iterating.

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

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

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

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0Oh, no you didn't, I just reread it and realized I sounded arrogant. :) That's true. I'll try that. Thanks!

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0This 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 trickjust knowing "if I had a way do this once, doing it a lot of times would be simple."

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0I'll try that. Thank you so much.

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