OpenStudy (anonymous):

Hi everyone. Can anyone tell me what's wrong with my code.. It's for problem set 1, problem 2 ## problem 2 out_balance= float(raw_input('The outstanding balance is: ' )) rate= float(raw_input('Annual interest rate as a decimal: ')) month = 0 min_payment = 10.0 balance=out_balance m_rate=rate/12.0 while balance > 0 : balance=out_balance min_payment+=10.0 while month < 12 and balance>0: month+=1 interest=balance*m_rate balance=interest+balance balance=balance-min_payment print 'monthly payment', min_payment print 'number of month', month print 'current balance', remained

4 years ago
OpenStudy (espex):

You go through your 2nd while and do not reset your month, this causes the 2nd while to evaluate to false after the first 12 iterations. Subsequently you are getting stuck in your 1st while and are not able to decrement balance, these two conditions put you into an infinite loop.

4 years ago
OpenStudy (anonymous):

I seem to be having trouble with the same problem. I get an answer printout however they don't make sense mathematically (monthly payment x months is less than the initial balance not accounting for interest). I can't seem to find what I'm doing wrong. Here is my code... Thank you very much. #paying the minimum problem 1 balance=int(raw_input('Enter the outstanding balance on your credit card')) x=float(raw_input('Enter the annual credit card interest rate as a decimal')) monthly_int=x/12 monthly_payment=0 while balance>0: monthly_payment += 10 num_months=0 while num_months< 12 and balance > 0: num_months += 1 interest=balance*monthly_int balance=balance+interest-monthly_payment balance=round(balance,2) print'RESULT' print 'Monthly payment to pay off debt in 1 year:',monthly_payment print 'Number of months needed:', num_months print 'Balance:', balance

4 years ago
OpenStudy (espex):

@david6014 Your problem centers around your 'balance' variable. Once you go through your first 12 iterations in your inner loop, you break out and do not reset your balance back to your original value. So as you are incrementing your payment, your balance is starting as the balance + interest - payments left from the previous 12 iterations. Change your code slightly and you should see an improvement in your calculations: old_bal = balance while balance>0: balance = old_bal monthly_payment += 10

4 years ago