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:
I've been stalking the group all morning and somnamniac's replies to some other questions have helped a lot.
Thanks in advance.
MIT 6.00 Intro Computer Science (OCW)
Stacey Warren - Expert brainly.com
Hey! We 've verified this expert answer for you, click below to unlock the details :)
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.
I got my questions answered at brainly.com in under 10 minutes. Go to brainly.com now for free help!
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?
sorry, I meant incrementing there, not iterating.
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?
Not the answer you are looking for? Search for more explanations.
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.
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!
Oh, no you didn't, I just reread it and realized I sounded arrogant. :)
That's true. I'll try that. Thanks!
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."
I'll try that. Thank you so much.
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.