Guest User

Untitled

a guest
Jul 23rd, 2018
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. balance = 999999
  2. annualInterestRate = 0.18
  3. monthly_interest_rate = annualInterestRate /12.0
  4. lower_bound = balance / 12.0
  5. upper_bound = (balance * (1 + monthly_interest_rate)**12) / 12.0
  6.  
  7. def calculate_balance(balance, fixed):
  8. month = 0
  9. while month < 12:
  10. balance = (balance - fixed) * (monthly_interest_rate + 1)
  11. month += 1
  12. balance
  13. return balance
  14.  
  15. while True:
  16. if abs(calculate_balance(balance, lower_bound) - balance) > 0.01:
  17. if calculate_balance(balance, lower_bound) > 0:
  18. mark = lower_bound
  19. lower_bound = (lower_bound + upper_bound) / 2
  20. elif calculate_balance(balance, lower_bound) < 0:
  21. upper_bound = lower_bound
  22. lower_bound = mark
  23. else:
  24. break
  25. print(lower_bound)
Add Comment
Please, Sign In to add comment