Quantcast

Got Homework?

Connect with other students for help. It's a free community.

  • across
    MIT Grad Student
    Online now
  • laura*
    Helped 1,000 students
    Online now
  • Hero
    College Math Guru
    Online now

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

MJL

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
  • one year ago

  • This Question is Open
  1. bwCA
    Best Response
    You've already chosen the best response.
    Medals 0

    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

    • one year ago
  2. MarzJon
    Best Response
    You've already chosen the best response.
    Medals 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

    • one year ago
  3. MJL
    Best Response
    You've already chosen the best response.
    Medals 0

    Thanks, And I am working on the 2008 course.

    • one year ago
  4. bwCA
    Best Response
    You've already chosen the best response.
    Medals 0

    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?

    • one year ago
  5. MJL
    Best Response
    You've already chosen the best response.
    Medals 0

    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?

    • one year ago
  6. bwCA
    Best Response
    You've already chosen the best response.
    Medals 0

    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.

    • one year ago
  7. rsmith6559
    Best Response
    You've already chosen the best response.
    Medals 0

    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?

    • one year ago
  8. MJL
    Best Response
    You've already chosen the best response.
    Medals 0

    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.

    • one year ago
  9. bwCA
    Best Response
    You've already chosen the best response.
    Medals 0

    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

    • one year ago
  10. rsmith6559
    Best Response
    You've already chosen the best response.
    Medals 0

    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!

    • one year ago
  11. bwCA
    Best Response
    You've already chosen the best response.
    Medals 0

    early optimization is the root of all evil

    • one year ago
  12. rsmith6559
    Best Response
    You've already chosen the best response.
    Medals 0

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

    • one year ago
  13. vipuljoshi92
    Best Response
    You've already chosen the best response.
    Medals 0

    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?

    • one year ago
  14. bwCA
    Best Response
    You've already chosen the best response.
    Medals 0

    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.

    • one year ago
  15. MJL
    Best Response
    You've already chosen the best response.
    Medals 0

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

    • one year ago
  16. bwCA
    Best Response
    You've already chosen the best response.
    Medals 0

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

    • one year ago
  17. vipuljoshi92
    Best Response
    You've already chosen the best response.
    Medals 0

    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

    • one year ago
  18. vipuljoshi92
    Best Response
    You've already chosen the best response.
    Medals 0

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

    • one year ago
    • Attachments:

See more questions >>>

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
  • 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.

This is the testimonial you wrote.
You haven't written a testimonial for Owlfred.