Stuck on problem set 1, problem 1- 6.00 fall 2008- I have no clue how to set this up, could someone please help me out?
One of the things to start with is finding the first say 10 primes and printing each one as you go. If you can write a program that does this reliably and mathematically, then you know you should be finding primes fine. Next, adjust the setting that limits you to 10 to 1000 and print the first 1000. Check the last ones against a list of prime numbers to make sure you have really got the program working right. Finally, move the print from inside your loop to outside so that it only prints the last one... or if you do a function have it return just the last one.
Some tips for finding primes: Divide by 2 and get the remainder. If it is 0, fail it. Divide by a range, starting at 3 and going up by 2 (so all odds) that continues until it is the tested number +1 (Range needs to be told to go past, or it won't reach.) If the remainder of division is 0 AND the divisor is not = to the quotient, fail it. Things that survive this should be primes. The goal there is simple. A prime is anything that only divides evenly by 1 and itself. Because it is hard to find these arbitrarily, you do a process of elimination. Anything that is dividable by other numbers is eliminated by the above looping test.
write out in words what you think you need to do - it helps organize your thoughts. then you can use it as a guide when writing your code
@bwCA Yah, psydocode (using words to describe the actions of the code) is one version of that which can be very useful at times. The more you get used to things, the less you use it. However, it can be really helpful at times. Just writing a plan, less psudocode and more like a detailed thought process, can be very powerful too. Both of those are ways of doing what you said. \(\ddot\smile\)
You want to initialize your variables first. Then get user input, tell it raw_input and then put your questions for the user in string form, like float (raw_input ("Enter your outstanding balance")). You want to get all the user input questions set up first. Oh, and be sure to use float before those, so it comes out as a decimal. That took me FOREVER to figure out. Then just get it to calculate! :) For example, interestpaid = (interestrate/12)*balance. You have to make sure you have all your given variables initialized first though. Hope this helps! :) Oh, and another thing that'd probably be good for you to have is the Python Wikibook. It helps me out so much I downloaded it.
Join our real-time social learning platform and learn together with your friends!