Skip to content

Commit 0922089

Browse files
committed
work
1 parent 3c00ff8 commit 0922089

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

Work/bounce.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
11
# bounce.py
22
#
33
# Exercise 1.5
4+
# Height for 10 bounces
5+
6+
height = 100 # in meters
7+
num_bounce = 1
8+
9+
while num_bounce <= 10:
10+
height = height * 3 / 5
11+
print(f"Bounce # {num_bounce}, Height: {round(height, 4)}m")
12+
num_bounce += 1
13+

Work/mortgage.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,36 @@
11
# mortgage.py
22
#
33
# Exercise 1.7
4+
5+
principal = 500_000.0
6+
rate = 0.05
7+
payment = 2684.11
8+
total_paid = 0.0
9+
month = 0
10+
11+
extra_payment_start_month = 61
12+
extra_payment_end_month = 108
13+
extra_payment = 1000
14+
15+
while principal > 0:
16+
month += 1
17+
principal = principal * (1+rate/12) - payment
18+
total_paid = total_paid + payment
19+
20+
if month >= extra_payment_start_month and month <= extra_payment_end_month:
21+
principal = principal - extra_payment
22+
total_paid = total_paid + extra_payment
23+
24+
# If remaining principal is less than the monthly payment, adjust the payment to principal left.
25+
if payment > principal:
26+
payment = principal * (1+rate/12)
27+
28+
print(month, round(total_paid,2), round(principal, 2))
29+
30+
31+
32+
print('Total paid', round(total_paid, 2))
33+
print('Months', month)
34+
35+
36+

0 commit comments

Comments
 (0)