Skip to content

Commit 3eae887

Browse files
authored
Update mortgage.py
1 parent 3c00ff8 commit 3eae887

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

Work/mortgage.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,22 @@
11
# mortgage.py
2-
#
3-
# Exercise 1.7
2+
principal = 500000.0
3+
rate = 0.05
4+
payment = 2684.11
5+
extra_payment = 1000.0
6+
total_paid = 0.0
7+
months = 0
8+
9+
# First year with extra payments
10+
for month in range(12):
11+
principal = principal * (1 + rate / 12) - (payment + extra_payment)
12+
total_paid += (payment + extra_payment)
13+
months += 1
14+
15+
# Remaining months without extra payments
16+
while principal > 0:
17+
principal = principal * (1 + rate / 12) - payment
18+
total_paid += payment
19+
months += 1
20+
21+
print('Total paid:', total_paid)
22+
print('Months required:', months)

0 commit comments

Comments
 (0)