Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Feb 24th, 2013  |  syntax: None  |  size: 1.35 KB  |  views: 86  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. ## ps1, prob 3
  2. print 'Given a starting balance and interest rate, this program will calculate your minimum monthly payment,'
  3. print 'that will pay off your balance in 12 months or less.'
  4.  
  5. balance = float(raw_input('Enter the outstanding balance on your credit card:'))
  6. interestrate = float(raw_input('Enter the annual credit card interest rate as a decimal:'))
  7.  
  8. lowerbound=balance/12
  9. upperbound=(balance*(1+(interestrate/12))**12)/12
  10. payment=(lowerbound+upperbound)/2
  11.  
  12. def twelvemonth ():
  13.     global payment
  14.     global lowerbound
  15.     global upperbound
  16.     month = 0
  17.  
  18.     while month <=11:
  19.         month = month + 1
  20.         if month==1:
  21.             calcbalance = balance
  22.         intowed = calcbalance*(interestrate/12)
  23.         calcbalance = calcbalance + intowed - payment
  24.         if -.12 <= calcbalance <= 0 and month == 12:
  25.             print 'Monthly payment to pay off debt in 1 year: $' + str(round(payment, 2))
  26.             print 'Number of months needed:  ' + str(month)
  27.             print 'Balance:  $' + str(round(calcbalance, 2))
  28.         if calcbalance < -.12 and month == 12:
  29.             upperbound=payment
  30.             payment=(payment+lowerbound)/2
  31.             twelvemonth ()
  32.         if calcbalance > 0 and month == 12:
  33.             lowerbound=payment
  34.             payment=(payment+upperbound)/2
  35.             twelvemonth ()
  36.  
  37. twelvemonth ()
clone this paste RAW Paste Data