Skip to content

Commit d237b0b

Browse files
committed
Updated to Exercise 2.10: Printing a formatted table
1 parent 4236e47 commit d237b0b

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

‎Work/report.py‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
# report.py
23
#
34
# Exercise 2.4
@@ -32,6 +33,13 @@ def read_prices(filename):
3233
return prices
3334

3435

36+
def make_report(portfolio, prices):
37+
changes = []
38+
for stock in portfolio:
39+
changes.append((stock['name'], stock['shares'], prices[stock['name']], prices[stock['name']] - stock['price']))
40+
return changes
41+
42+
3543
portfolio = read_portfolio('Data/portfolio.csv')
3644
prices = read_prices('Data/prices.csv')
3745

@@ -48,3 +56,7 @@ def read_prices(filename):
4856
print(f'Current value: {current_value}')
4957

5058
print(f'Gain: {total_value:0.2f}' if total_value > 0 else f'Loss: {-total_value:0.2f}')
59+
60+
report = make_report(portfolio, prices)
61+
for name, shares, price, change in report:
62+
print(f'{name:>10s} {shares:>10d} {price:>10.2f} {change:>10.2f}')

0 commit comments

Comments
 (0)