Visitar URL original
implement section 1 exercises · dabeaz-course/practical-python@0edb50a · GitHub
Skip to content

Commit 0edb50a

Browse files
author
iram lee
committed
implement section 1 exercises
1 parent 8735c30 commit 0edb50a

3 files changed

Lines changed: 45 additions & 0 deletions

File tree

‎Work/bounce.py‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
# bounce.py
22
#
33
# Exercise 1.5
4+
height = 100
5+
for i in range(1, 11):
6+
height = (height * 3) / 5
7+
print(i, round(height, 4))

‎Work/mortgage.py‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,29 @@
11
# mortgage.py
22
#
33
# Exercise 1.7
4+
# mortgage.py
5+
6+
principal = 500000.0
7+
rate = 0.05
8+
payment = 2684.11
9+
total_paid = 0.0
10+
month = 0
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+
extra_pay = 0
18+
if month >= extra_payment_start_month and month <= extra_payment_end_month:
19+
extra_pay = extra_payment
20+
if payment >= principal * (1+rate/12):
21+
payment = principal * (1+rate/12)
22+
extra_pay = 0
23+
principal = principal * (1+rate/12) - (payment + extra_pay)
24+
total_paid = total_paid + (payment + extra_pay)
25+
print(month, round(total_paid, 2), round(principal, 2))
26+
27+
28+
print('Total paid', round(total_paid, 2))
29+
print('Over ', month, ' months')

‎Work/sears.py‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# sears.py
2+
3+
bill_thickness = 0.11 * 0.001 # Meters (0.11 mm)
4+
sears_height = 442 # Height (meters)
5+
num_bills = 1
6+
day = 1
7+
8+
while num_bills * bill_thickness < sears_height:
9+
print(day, num_bills, num_bills * bill_thickness)
10+
day = day + 1
11+
num_bills = num_bills * 2
12+
13+
print('Number of days', day)
14+
print('Number of bills', num_bills)
15+
print('Final height', num_bills * bill_thickness)

0 commit comments

Comments
 (0)