## MJL 2 years ago I've been trying to do the 1st problem in problem set one for a couple hours with no luck. I am completely new to programming. Could anyone point me in the right direction and help me get started?

• This Question is Open
1. bwCA

which course? 2008 or 2011? Write down on a piece of paper the steps you need to take to solve the problem try to break the solution up into chunks and write code for each of those chunks once you start coding refer to what you wrote down and once you start debugging, update what you wrote down. do you need a loop? do you need a variable to hold the state of something? what data types might? you need? you might want to take a stroll thru the Tutorial, practicing/trying the examples given; stroll as far and as often as you can - it will be worthwhile. http://docs.python.org/2.7/tutorial/index.html the help file is your friend

2. MarzJon

"try to break the solution up into chunks and write code for each of those chunks" -bwCA A technique you'd find useful would be writing "Pseudocode". http://en.wikipedia.org/wiki/Pseudocode

3. MJL

Thanks, And I am working on the 2008 course.

4. bwCA

1000th prime number? write a bit of code that will figure out if a number is prime. run that bit of code till it has found 1000 of them. things to think about: are you going to 'keep' all the primes or just the most recent prime found how will you know when you have 1000 of them?

5. MJL

I was thinking (and this could be totally wrong) that maybe I would need to make them form into a touple or a list, and then pull out the 1000th one similar to what he was showing in the video. There is probably an easier way to find the 1000th one though. Also, I am having trouble establishing good variables when I start, could you help me with that?

6. bwCA

that sounds like a good idea - every time you find a prime, put it in a list. when you are done, pull off the last one.

7. rsmith6559

The main difference between lists and tuples is that tuples are immutable. Tuples can't be changed, like added to. You'll see some "adds", but what actually happens is that a new tuple is made that has the old tuple plus the so-called addition, and it's assigned to the original name. It isn't the same object. What help do you want with variables?

8. MJL

So, if I wanted to add all of the primes, I should add them to a list instead of a tuple? And with the variables I am having trouble finding a good starting point because I am not entirely sure how to make the test that i need to loop in order to find prime numbers. I have been thinking that I need to start off with x=1 and then divide it checking to see if any numbers below it divide evenly by using the %. Then adding the primes to the list and adding 2 to x ( because only the odds should be prime.) 1st of all I don't know if this is a good/the right way to go about this. Also I don't know how to create a variable that will allow me to divide like this. My original thought was to divide by x-1, but that only allows me to go one number lower, when I need to go continuously lower. Sorry for the long response, and thank you for helping me. I'm very new to this but I really want to get better.

9. bwCA

10. rsmith6559

You have a solid starting point to writing a program that will work. Think a little more about the characteristics of prime, and non-prime numbers. There are characteristics that will suggest some major speed ups!

11. bwCA

early optimization is the root of all evil

12. rsmith6559

And unneeded brute force will give you plenty of time to ponder it, too.

13. vipuljoshi92

I am also stuck in this program. I managed to get odd numbers, but then I want to find prime numbers from them by dividing every number I from 2 to I-1. But I am not getting there..cn I post my code here ? is it allowed?

14. bwCA

you might want to start a new thread so others can see it it's ok to post your code for the OCW courses, the EDX course might have stricter rules please use a code pasting site: - http://dpaste.com - http://pastebin.com - http://www.repl.it/ - http://pastie.org - http://codepad.org - http://ideone.com paste your code there and post the link here. select Python syntax highlighting when u paste.

15. MJL

So I've come up with a way to find prime numbers, I just can't seem to make it find specifically the 1000th

16. bwCA

find the first one, then the second one then the ........... 1000th one, then stop.

17. vipuljoshi92

if you want to print only the 1000th prime number then assign that value to anything new say final, then get out of your loop and print final. this will find the prime numbers in background and print only the final prime number. So you would like to stop at that number

18. vipuljoshi92

and ya..do remove the cmmand to print rest of the primes. i hope you get it