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.
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
"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
Thanks, And I am working on the 2008 course.
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?
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?
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.
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?
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.
if you decide to keep all your primes, you can put them in a tuple or a list. sometimes lists are easier to work with because they have so many methods. The advantage of tuples are that they are immutable so you can't accidently change them. as to where to start.. The best way to start is to just start. It doesn't have to be perfect or 'the best' the first time - in fact it mostly never will be. You are off to a good start, you have some ideas and you have written them down. now try them out. One of the great things about Python is that you can try out small pieces of code in the shell to see how they work and see if that is what you want. Windows, Mac or Linux?? Have you been thru the tutorial in the Python documentation? It might really help you. Read thru it and practice all the examples given - even if it doesn't quite make sense, read it and practice the examples - hmmm i just got stuck reading more stuff in the tutorial, every time i go look at it i see something 'new' or forgotten and then i spend time trying it and figuring it out -i've done that a lot of times. i played around a bit with your prime problem - here is the result, you can see that i made a couple mistakes http://pastie.org/7353299 make sure you use a code pasting site when you want us to look at your code - here are a few (there are many): http:\\dpaste.com http:\\pastebin.com http:\\pastie.org
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!
early optimization is the root of all evil
And unneeded brute force will give you plenty of time to ponder it, too.
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?
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.
So I've come up with a way to find prime numbers, I just can't seem to make it find specifically the 1000th
find the first one, then the second one then the ........... 1000th one, then stop.
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
and ya..do remove the cmmand to print rest of the primes. i hope you get it