Skip to content

Commit 4be0cbc

Browse files
committed
Changes to be committed:
modified: Work/mortgage.py new file: Work/mortgage_extra_payment2.py new file: Work/mortgage_extra_payment3.py Testing Commit after completing mortage examples.
1 parent dbfcbef commit 4be0cbc

File tree

3 files changed

+69
-1
lines changed

3 files changed

+69
-1
lines changed

Work/mortgage.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
rate = 0.05
77
payment = 2684.11
88
total_paid = 0.0
9-
9+
month
1010
while principal > 0:
1111
principal = principal * (1+rate/12) - payment
1212
total_paid = total_paid + payment

Work/mortgage_extra_payment2.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# mortgage.py
2+
#
3+
# Exercise 1.7
4+
#
5+
# Dave makes an extra payment of $1000/month between month
6+
# This logic makes Dave overshoot the principal (i.e. makes the principal neg)
7+
# Fixed in mortgage extra_payment3.py
8+
9+
principal = 500000.0
10+
rate = 0.05
11+
payment = 2684.11
12+
total_paid = 0.0
13+
month = 1
14+
15+
extra_payment_start_month=60
16+
extra_payment_end_month=108
17+
extra_payment=1000
18+
19+
while principal > 0:
20+
21+
principal = principal * (1+rate/12) - payment
22+
total_paid = total_paid + payment
23+
24+
if ( extra_payment_start_month <= month <= extra_payment_end_month):
25+
principal = principal - extra_payment
26+
total_paid = total_paid + extra_payment
27+
28+
print(month,round(total_paid,2),round(principal,2))
29+
30+
month += 1
31+
32+
print('Total paid', round(total_paid,2))

Work/mortgage_extra_payment3.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# mortgage.py
2+
#
3+
# Exercise 1.7
4+
#
5+
# Dave makes an extra payment of $1000/month between month
6+
# This logic makes Dave overshoot the principal (i.e. makes the principal neg)
7+
# Fixed in this file
8+
9+
principal = 500000.0
10+
rate = 0.05
11+
payment = 2684.11
12+
total_paid = 0.0
13+
month = 1
14+
15+
extra_payment_start_month=60
16+
extra_payment_end_month=108
17+
extra_payment=1000
18+
19+
while principal > 0:
20+
21+
total_payment = payment
22+
if ( extra_payment_start_month <= month <= extra_payment_end_month):
23+
total_payment += extra_payment
24+
25+
if (principal * (1+rate/12) - total_payment) < 0 :
26+
total_payment = principal*(1+rate/12)
27+
28+
principal = principal * (1+rate/12) - total_payment
29+
total_paid = total_paid + total_payment
30+
31+
32+
print(month,round(total_paid,2),round(principal,2))
33+
34+
month += 1
35+
36+
print('Total paid', round(total_paid,2))

0 commit comments

Comments
 (0)