Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- balance = 999999
- annualInterestRate = 0.18
- monthly_interest_rate = annualInterestRate /12.0
- lower_bound = balance / 12.0
- upper_bound = (balance * (1 + monthly_interest_rate)**12) / 12.0
- def calculate_balance(balance, fixed):
- month = 0
- while month < 12:
- balance = (balance - fixed) * (monthly_interest_rate + 1)
- month += 1
- balance
- return balance
- while True:
- if abs(calculate_balance(balance, lower_bound) - balance) > 0.01:
- if calculate_balance(balance, lower_bound) > 0:
- mark = lower_bound
- lower_bound = (lower_bound + upper_bound) / 2
- elif calculate_balance(balance, lower_bound) < 0:
- upper_bound = lower_bound
- lower_bound = mark
- else:
- break
- print(lower_bound)
Add Comment
Please, Sign In to add comment