Skip to content

Commit c6c4a0f

Browse files
committed
Snapshot from lesson 1
1 parent 3c00ff8 commit c6c4a0f

5 files changed

Lines changed: 84 additions & 6 deletions

File tree

Work/bounce.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1-
# bounce.py
2-
#
3-
# Exercise 1.5
1+
# A rubber ball is dropped from a height of 100m and each time it hits the ground, it bounces
2+
# back to 3/5 the height it fell.
3+
# Print a table showing the height of the first 10 bounces.
4+
5+
height = 100
6+
7+
for i in range(10):
8+
height = height * 3 / 5
9+
print(i+1, round(height, ndigits=4))

Work/hello.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
print('hello world!')

Work/mortgage.py

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,24 @@
1-
# mortgage.py
2-
#
3-
# Exercise 1.7
1+
# Dave has decided to take out a 30 years mortgage of $500,000.
2+
# The interest rate is 5%, the monthly payment is $2684.11
3+
# Calculate the total amount that Dave will have to pay over the
4+
# life of the mortgage
5+
6+
# Suppose Dave has an extra payment of $1000/month for the first 12 months
7+
# of the mortgage.
8+
9+
principal = 500000.0
10+
rate = 0.05
11+
payment = 2684.11
12+
total_paid = 0
13+
number_months = 0
14+
15+
while principal > 0:
16+
principal = principal * (1+rate/12) - payment
17+
total_paid = total_paid + payment
18+
if number_months < 12:
19+
total_paid = total_paid + 1000
20+
principal = principal - 1000
21+
number_months = number_months + 1
22+
23+
print('Total paid', round(total_paid, ndigits=2))
24+
print('Number of Months', number_months)

Work/sears.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# On day one you deposit one bill on the ground in front of Sears tower.
2+
# Every day you go out and double the number of bills.
3+
# How many days will it take for the height of the bill stack to exceed the height of the tower?
4+
5+
bill_thickness = 0.11 * 0.001 # meters
6+
sears_height = 442 # height in meters
7+
num_bills = 1
8+
day = 1
9+
10+
while num_bills * bill_thickness < sears_height:
11+
print(day, num_bills, num_bills * bill_thickness)
12+
day = day + 1
13+
num_bills = num_bills * 2
14+
15+
print('Number of days', day)
16+
print('Number of bills', num_bills)
17+
print('Final height', num_bills * bill_thickness)

Work/variable_mortgage.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Dave has decided to take out a 30 years mortgage of $500,000.
2+
# The interest rate is 5%, the monthly payment is $2684.11
3+
# Calculate the total amount that Dave will have to pay over the
4+
# life of the mortgage
5+
6+
# User input is used to set custom payments
7+
8+
principal = 500000.0
9+
rate = 0.05
10+
payment = 2684.11
11+
total_paid = 0
12+
number_months = 0
13+
extra_payment_start_month = 1000000000
14+
extra_payment_end_month = extra_payment_start_month
15+
extra_payment = 0
16+
17+
extra_payment = int(input('Extra payment / month: '))
18+
if extra_payment > 0:
19+
extra_payment_start_month = int(input('Extra payment start month: '))
20+
extra_payment_end_month = int(input('Extrapoayment end month: '))
21+
22+
while principal > 0:
23+
principal = principal * (1+rate/12) - payment
24+
total_paid = total_paid + payment
25+
number_months = number_months + 1
26+
if number_months >= extra_payment_start_month and number_months <= extra_payment_end_month:
27+
total_paid = total_paid + extra_payment
28+
principal = principal - extra_payment
29+
print(number_months, round(total_paid, 2), round(principal, 2))
30+
31+
32+
print('Total paid', round(total_paid, ndigits=2))
33+
print('Number of Months', number_months)

0 commit comments

Comments
 (0)