Guest User

Untitled

a guest
Jun 30th, 2013
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.38 KB | None | 0 0
  1. # Debt Payment Calculator
  2.  
  3. #Takes in the necessary variables for the calculator
  4. outstanding_bal = float(raw_input('Please enter the outstanding balance on your credit card: '))
  5. annual_interest = float(raw_input('Please enter the annual credit card interest rate as a decimal: '))
  6. monthly_interest = annual_interest/12.0
  7.  
  8. outstanding_bal_copy = outstanding_bal
  9.  
  10. month = 1
  11.  
  12. lower_payment = outstanding_bal_copy / 12.0
  13. upper_payment = (outstanding_bal_copy *(1+(annual_interest/12))**12.0)/12.0
  14.  
  15. monthly_payment = (upper_payment + lower_payment) / 2.0
  16.  
  17.  
  18. #Finds the optimal monthly payment with interest
  19. while (outstanding_bal_copy > 0):
  20.     ##print monthly_payment
  21.     ##print outstanding_bal_copy
  22.     outstanding_bal_copy = round((outstanding_bal_copy * (1 + monthly_interest) - monthly_payment), 2)        
  23.     if month > 12:
  24.         month = 1
  25.         if outstanding_bal_copy > 0:
  26.             upper_payment = monthly_payment
  27.         else:
  28.             lower_payment = monthly_payment
  29.         monthly_payment = (upper_payment + lower_payment) / 2.0
  30.         outstanding_bal_copy = outstanding_bal
  31.         continue
  32.     month += 1
  33.  
  34. month = month - 1
  35.  
  36. if outstanding_bal_copy <= 0:
  37.     print 'RESULT'
  38.     print 'Monthly payment to pay off debt in 1 year: $' + str(monthly_payment)
  39.     print 'Number of months needed: ' + str(month)
  40.     print 'Balance: $' + str(outstanding_bal_copy)
Advertisement
Add Comment
Please, Sign In to add comment