Skip to content

Commit 9392600

Browse files
committed
Exercise 1.17: f-strings
1 parent 8b01fa2 commit 9392600

1 file changed

Lines changed: 31 additions & 0 deletions

File tree

‎Work/mortgage.py‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,34 @@
11
# mortgage.py
22
#
33
# Exercise 1.7
4+
principal = 500000.0
5+
rate = 0.05
6+
payment = 2684.11
7+
total_paid = 0.0
8+
extra_payment_start_month = 60
9+
extra_payment_end_month = 108
10+
extra_payment = 1000
11+
month_counter = 0
12+
13+
while principal > 0:
14+
month_counter += 1
15+
if month_counter == extra_payment_start_month:
16+
payment += extra_payment
17+
elif month_counter == extra_payment_end_month + 1:
18+
payment -= extra_payment
19+
20+
principal = principal * (1 + rate / 12)
21+
22+
if principal > payment:
23+
total_paid += payment
24+
principal -= payment
25+
else:
26+
total_paid += principal
27+
principal = 0
28+
29+
print(f"Month #{month_counter:4d} | Total paid: {total_paid:0.2f} | Principal: {principal:0.2f}")
30+
31+
32+
print(f'\n=============================')
33+
print('Total paid', round(total_paid, 2))
34+
print('Months', month_counter)

0 commit comments

Comments
 (0)