I am currently working on program to pay off credit card balance in one year. My initial code is below, which seems to be doing the right thing if I run a print statement, but it generates an infinite loop as I have not added an if statement, which is where I am a bit stuck, as I am not sure how to structure the if statement... should this be for when balance <= 0? is an else required? Here is code thus far: >>> balance = 4000.00 >>> monthly_int = 0.18/12 >>> month = 1 >>> mmp = 0 >>> while month <= 12: mmp += 10 balance = (balance * (1 + monthly_int) - mmp)
I just realize even this initial code is not quite right... hints welcome.
It would help to know what the actual mathematical assumptions are. So every month, interest accumulates on the current balance and the monthly payment is deducted? And you want to find the monthly payment by guessing and checking? You increase the monthly payment by 10 until you find one which pays it off in a year? In that case, you need to make sure the balance is reset after you change the monthly payment. Also if the balance is less than 0 after any particular year, then you know to stop.
Wio, all your assumptions are correct. sorry I was not more detailed but I ran out of room. Re making sure the balance is reset....do I need to make separate while statements? The code as I have written it increments the payment $10 month by month and this is applied to the balance but this is not exactly what I am after... I want a complete separate repayment scenario for each $10 increment over a 12 month period.
Ps: so basically I am not sure how I would make sure the balance is reset. thanks!
You need to have a variable which stores the initial balance and one which stores the current balance. At the beginning of each attempt, set the balance to the initial balance.
I think I got it finally... did have to use a nested while statement. had some help from my nephew and we hammered it out together. the nested while has the reset balance. I can see this MIT programming thing is going to be a wild ride :)
Join our real-time social learning platform and learn together with your friends!