A community for students. Sign up today!
Here's the question you clicked on:
 0 viewing
 one year 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?
 one year 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

bwCA
 one year ago
Best ResponseYou've already chosen the best response.0which 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

MarzJon
 one year ago
Best ResponseYou've already chosen the best response.0"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

MJL
 one year ago
Best ResponseYou've already chosen the best response.0Thanks, And I am working on the 2008 course.

bwCA
 one year ago
Best ResponseYou've already chosen the best response.01000th 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?

MJL
 one year ago
Best ResponseYou've already chosen the best response.0I 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?

bwCA
 one year ago
Best ResponseYou've already chosen the best response.0that 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.

rsmith6559
 one year ago
Best ResponseYou've already chosen the best response.0The 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 socalled addition, and it's assigned to the original name. It isn't the same object. What help do you want with variables?

MJL
 one year ago
Best ResponseYou've already chosen the best response.0So, 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 x1, 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.

bwCA
 one year ago
Best ResponseYou've already chosen the best response.0if 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

rsmith6559
 one year ago
Best ResponseYou've already chosen the best response.0You have a solid starting point to writing a program that will work. Think a little more about the characteristics of prime, and nonprime numbers. There are characteristics that will suggest some major speed ups!

bwCA
 one year ago
Best ResponseYou've already chosen the best response.0early optimization is the root of all evil

rsmith6559
 one year ago
Best ResponseYou've already chosen the best response.0And unneeded brute force will give you plenty of time to ponder it, too.

vipuljoshi92
 one year ago
Best ResponseYou've already chosen the best response.0I 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 I1. But I am not getting there..cn I post my code here ? is it allowed?

bwCA
 one year ago
Best ResponseYou've already chosen the best response.0you 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.

MJL
 one year ago
Best ResponseYou've already chosen the best response.0So I've come up with a way to find prime numbers, I just can't seem to make it find specifically the 1000th

bwCA
 one year ago
Best ResponseYou've already chosen the best response.0find the first one, then the second one then the ........... 1000th one, then stop.

vipuljoshi92
 one year ago
Best ResponseYou've already chosen the best response.0if 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

vipuljoshi92
 one year ago
Best ResponseYou've already chosen the best response.0and ya..do remove the cmmand to print rest of the primes. i hope you get it
Ask your own question
Ask a QuestionFind 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.