Skip to content

Commit 183382b

Browse files
committed
Exercises 2.10-2.11
1 parent 675c9ad commit 183382b

1 file changed

Lines changed: 22 additions & 6 deletions

File tree

‎Work/report.py‎

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,34 @@ def read_prices(filename):
3131
pass
3232
return prices
3333

34+
def make_report(stocklist, pricelist):
35+
report = []
36+
for h in stocklist:
37+
name = h['name']
38+
report.append((name, h['shares'], pricelist[name],
39+
pricelist[name]-h['price']))
40+
return report
41+
3442
portfolio = read_portfolio('Data/portfolio.csv')
3543
prices = read_prices('Data/prices.csv')
3644

45+
report = make_report(portfolio, prices)
46+
47+
headers = ('Name', 'Shares', 'Price', 'Change')
48+
print('%10s %10s %10s %10s' % headers)
49+
print('%10s %10s %10s %10s' % (('-'*10,)*4))
50+
for r in report:
51+
print('%10s %10d %10.2f %10.2f' %r)
52+
3753
portfolio_value = 0.0
3854
for h in portfolio:
3955
portfolio_value += h['shares']*h['price']
4056

41-
print(f'Original value:{portfolio_value:10.2f}')
57+
# print(f'Original value:{portfolio_value:10.2f}')
4258

43-
current_value = 0.0
44-
for h in portfolio:
45-
current_value += h['shares']*prices[h['name']]
59+
#current_value = 0.0
60+
#for h in portfolio:
61+
# current_value += h['shares']*prices[h['name']]
4662

47-
print(f'Current value: {current_value:10.2f}')
48-
print('Gain: {:10.2f}'.format(current_value - portfolio_value))
63+
#print(f'Current value: {current_value:10.2f}')
64+
#print('Gain: {:10.2f}'.format(current_value - portfolio_value))

0 commit comments

Comments
 (0)