-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproblem2debt.py
More file actions
22 lines (18 loc) · 858 Bytes
/
problem2debt.py
File metadata and controls
22 lines (18 loc) · 858 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# Paste your code into this box
Monthly_payment_lower_bound = balance / 12
Monthly_payment_upper_bound = (balance * (1 + annualInterestRate/12)**12) / 12.0
Lowest_Payment=(Monthly_payment_lower_bound+Monthly_payment_upper_bound)/2
while 1:
remainBalance=balance
for i in range(1,13):
remainBalance=remainBalance - Lowest_Payment
remainBalance=remainBalance * (1+annualInterestRate/12)
if(abs(remainBalance-0)<=0.001):
break
if(remainBalance>0):
Monthly_payment_lower_bound=Lowest_Payment
Lowest_Payment=(Monthly_payment_lower_bound+Monthly_payment_upper_bound)/2
if(remainBalance<0):
Monthly_payment_upper_bound=Lowest_Payment
Lowest_Payment=(Monthly_payment_lower_bound+Monthly_payment_upper_bound)/2
print 'Lowest Payment: '+str(round(Lowest_Payment,2))