nicokruk

MIT 6.00SC - Problem Set 1 - Problem 3

Jun 18th, 2012
519
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.98 KB | None | 0 0
  1. balance = float(raw_input('Enter the outstanding balance on your credit card: '))
  2. annual_interest = float(raw_input('Enter the annual credit card interest rate as a decimal: '))
  3. minimum_payment = balance/12.0
  4. maximum_payment = (balance * (1 + (annual_interest / 12.0)) * 12.0) / 12.0
  5. new_balance = balance
  6.  
  7. while balance != 0.0:
  8.     monthly_payment = (minimum_payment + maximum_payment) / 2.0
  9.     for month in range(1,13):
  10.         new_balance = round((new_balance * (1 + (annual_interest / 12.0)) - monthly_payment),2)
  11.         if new_balance <= 0.0:
  12.             break
  13.     if new_balance == 0.0:
  14.         balance = new_balance
  15.     elif new_balance > 0.0:
  16.         minimum_payment = monthly_payment
  17.         new_balance = balance
  18.     else:
  19.         maximum_payment = monthly_payment
  20.         new_balance = balance
  21.    
  22. print 'RESULT'
  23. print 'Monthly payment to pay off debt in 1 year:',round(monthly_payment,2)
  24. print 'Number of months needed:',month
  25. print 'Balance:',round(balance,2)
Advertisement
Add Comment
Please, Sign In to add comment