Skip to content

Commit 2f326bd

Browse files
committed
latest updates
1 parent 88f8376 commit 2f326bd

5 files changed

Lines changed: 91 additions & 0 deletions

File tree

Work/bounce.py

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

Work/mortgage.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,30 @@
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+
month = 0
9+
extra_payment_start_month = 49
10+
extra_payment_end_month = extra_payment_start_month + 4*12
11+
extra_payment = 1000
12+
13+
while principal > 0:
14+
month = month + 1
15+
if month >= extra_payment_start_month and month < extra_payment_end_month:
16+
extraPmt = extra_payment
17+
else:
18+
extraPmt = 0.0
19+
if principal * (1+rate/12) - payment - extraPmt < 0:
20+
if principal * (1+rate/12) - payment < 0:
21+
payment = principal * (1+rate/12)
22+
extraPmt = 0
23+
else: # ExtraPmt puts it over
24+
extraPmt = principal * (1+rate/12) - payment
25+
principal = principal * (1+rate/12) - payment - extraPmt
26+
total_paid = total_paid + payment + extraPmt
27+
print(f'Month: {month} Total Paid: ${total_paid:0.2f} Remaining: ${principal:0.2f}')
28+
29+
print('Total Paid', total_paid)
30+
print('Total Months', month)

Work/pcost.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,25 @@
11
# pcost.py
22
#
33
# Exercise 1.27
4+
import sys
5+
def portfolio_cost(filename):
6+
import csv
7+
f = open(filename)
8+
rows = csv.reader(f)
9+
totalCost = 0
10+
header = next(rows)
11+
for row in rows:
12+
try:
13+
rowCost = int(row[1]) * float(row[2])
14+
totalCost = totalCost + rowCost
15+
except ValueError:
16+
print('Data error', row)
17+
return totalCost
18+
19+
if len(sys.argv) == 2:
20+
filename = sys.argv[1]
21+
else:
22+
filename='Data/portfolio.csv'
23+
24+
cost = portfolio_cost(filename)
25+
print('The total cost is: ', cost)

Work/sears.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# sears tower problem
2+
# tower 1450 ft
3+
# dollar bill 0.004
4+
towerHtFt = 1450.0
5+
towerHtIn = towerHtFt * 12
6+
print("Height in In", towerHtIn)
7+
billHt = .004
8+
pileHt = billHt
9+
billCount = 1
10+
day = 1
11+
while pileHt < towerHtIn :
12+
pileHt = pileHt * 2
13+
day = day + 1
14+
print(day, pileHt)
15+
16+
print("bills required", pileHt/.004)
17+
print("total days", day)

sears.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# sears tower problem
2+
# tower 1450 ft
3+
# dollar bill 0.004
4+
towerHtFt = 1450.0
5+
towerHtIn = towerHtFt * 12
6+
print("Height in In", towerHtIn)
7+
billHt = .004
8+
pileHt = billHt
9+
billCount = 1
10+
day = 1
11+
while pileHt < towerHtIn :
12+
pileHt = pileHt * 2
13+
day = day + 1
14+
print(day, pileHt)
15+
16+
print("bills required", pileHt/.004)
17+
print("total days", day)

0 commit comments

Comments
 (0)