Skip to content

Commit ae075d4

Browse files
committed
exercise 3.1
1 parent 952a2c0 commit ae075d4

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

Work/report.py

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,17 +45,12 @@ def make_report(portfolio, prices):
4545
return rows
4646

4747

48-
portfolio = read_portfolio('Data/portfoliodate.csv')
49-
#portfolio = read_portfolio(input("Enter the filename: "))
50-
prices = read_prices('Data/prices.csv')
51-
52-
53-
report = make_report(portfolio, prices)
54-
header = ('Name', 'Shares', 'Price', 'Change')
55-
print("%10s %10s %10s %10s" %header)
56-
print(("-" * 10 + " ") * len(header))
57-
for name, shares, price, change in report:
58-
print(f"{name:>10s} {shares:>10d} {f'${price:.2f}':>10} {change:>10.2f}")
48+
def print_report(report):
49+
header = ('Name', 'Shares', 'Price', 'Change')
50+
print("%10s %10s %10s %10s" %header)
51+
print(("-" * 10 + " ") * len(header))
52+
for name, shares, price, change in report:
53+
print(f"{name:>10s} {shares:>10d} {f'${price:.2f}':>10} {change:>10.2f}")
5954

6055
##cost = 0
6156
#for share in portfolio:
@@ -69,3 +64,13 @@ def make_report(portfolio, prices):
6964
#print(f"Current value: {curr_val}")
7065
#print(f"Profit: {curr_val - cost}")
7166
#
67+
def main():
68+
portfolio = read_portfolio('Data/portfoliodate.csv')
69+
#portfolio = read_portfolio(input("Enter the filename: "))
70+
prices = read_prices('Data/prices.csv')
71+
report = make_report(portfolio, prices)
72+
print_report(report)
73+
74+
if __name__ == "__main__":
75+
main()
76+

0 commit comments

Comments
 (0)