Hello all, again. So basically I'm just struggling with how to 'translate' something into python: I want to do "x" every month. So far my code for problem 1b is: balance = raw_input('Vot is the outstanding balance?') InrAn = raw_input('Vot is the annual interest rate as a decimal?') InrAn = float(InrAn) balance = float(balance) numMonths = 1 monthPay = 10 monthInr = InrAn/12.0 while balance >= 0 etc. I'm on the 1st problem that's been set, btw xD
One thing that I'm not wild about is changing the type of data that balance and InrAn hold. You could put the entire raw_input() function into the float() function, like this: foo = float( raw_input( "Enter a decimal number: " ) ) raw_input() returns what the user entered as a string. When balance is started as a string, and then changed to a float after the float() function, it's neither pretty or possible in many other languages. One of the most important skills that a programmer needs to develop is to take a problem and break it down into smaller sub-problems and then break the sub-problems into sub-sub-problems and continue this until a small block of code, usually less than 20 lines, can solve this part of a problem. Breaking down ( decomposing ) a problem like this usually gives you the organization of the solution ( program ) too.
google it
First of all, it would help if your variable names were a bit more descriptive. As @rsmith6559 said, you can wrap your input with float() to clean it up and do it on one line for each of the inputs. Remember you must also input the minimum monthly payment. As far as the actual loop for problem 1 of problem set 1, you want to figure out the credit card balance after a year, so a for loop would work here. Inside the loop its simply arithmetic as outlined in the instructions: Minimum monthly payment = minimum monthly payment rate x remaining balance Interest paid = balance x interest rate / 12 Principal paid = Minimum monthly payment - interest paid Remaining balance = balance - principal I tried to be vague as to not give the whole problem away, so if you need more help let me know.
Thanks. And yeah, I get how because I'm stuck on such a basic part it can be hard to give me hints!
Join our real-time social learning platform and learn together with your friends!