Skip to content

Commit 8990317

Browse files
committed
updated'
'
1 parent 2380fa4 commit 8990317

5 files changed

Lines changed: 107 additions & 2 deletions

File tree

Work/mortgage.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,22 @@
11
# mortgage.py
22
#
33
# Exercise 1.7
4+
5+
principal = 500000.0
6+
rate = 0.05
7+
payment = 2684.11
8+
total_paid = 0.0
9+
num_of_payments = 0
10+
sum_of_payments = 0
11+
12+
13+
14+
while principal > 0:
15+
if num_of_payments < 12:
16+
payment = 3684.11
17+
else:
18+
payment = 2684.11
19+
principal = principal * (1+rate/12) - payment
20+
total_paid = payment + total_paid
21+
num_of_payments += 1
22+
print(num_of_payments, 'Total paid:' + str(total_paid))

Work/pcost.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
#!/usr/bin/python3
12
# pcost.py
2-
#
3-
# Exercise 1.27
3+
4+
5+
total_cost = 0
6+
with open('Data/portfolio.csv', 'rt') as filename:
7+
header_data = next(filename).split(',')
8+
content = filename.read()
9+
print(header_data)
10+
for line in content:
11+
#print(content)
12+
print(line)
13+
#num_of_shares = float(line[1])
14+
#purchase_price = float(line[2])
15+
#total_cost += num_of_shares * purchase_price

Work/portfolio_cost.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#
2+
3+
def portfolio_cost(filename):
4+
'''
5+
finds the total cost of portfolio investment defined in a particular file
6+
'''
7+
total_cost = 0.0
8+
9+
with open(filename, 'rt') as f:
10+
headers = next(f)
11+
for line in f:
12+
row = line.split(',')
13+
nshares = int(row[1])
14+
price = float(row[2])
15+
total_cost += nshares * price
16+
17+
print('Total cost', total_cost)
18+
19+
20+

Work/report.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,40 @@
11
# report.py
22
#
33
# Exercise 2.4
4+
5+
# __file__ = 'Data/portfolio.csv'
6+
7+
8+
9+
# reads portfolio files
10+
# define fn read_portfolio(filename)
11+
# list of tuples is output
12+
13+
portfolio = []
14+
15+
16+
def read_portfolio(filename):
17+
18+
for row in rows:
19+
holding = (row[0], int(row[1]), float(row[2]))
20+
portfolio.append(holding)
21+
22+
23+
24+
25+
26+
27+
import csv
28+
29+
def portfolio_cost(filename):
30+
'''Computes the total cost (shares*price) of a portfolio file'''
31+
total_cost = 0.0
32+
33+
with open(filename, 'rt') as f:
34+
rows = csv.reader(f)
35+
headers = next(rows)
36+
for row in rows:
37+
nshares = int(row[1])
38+
price = float(row[2])
39+
total_cost += nshares * price
40+
return total_cost

Work/sears.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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+
days = day
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)

0 commit comments

Comments
 (0)