Skip to content

Commit e415f0e

Browse files
committed
exercise 3.16
1 parent 4343764 commit e415f0e

File tree

2 files changed

+49
-9
lines changed

2 files changed

+49
-9
lines changed

Work/pcost.py

Lines changed: 39 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,45 @@
77

88
# file = "Data/portfolio.csv"
99

10-
def portfolio_cost(file):
10+
def portfolio_cost(filename):
1111
portfolio = report.read_portfolio(filename)
12-
return sum([s['shares']*s['price'] for s in portfolio])
12+
return sum([s['shares'] * s['price'] for s in portfolio])
13+
14+
def main(args):
15+
if len(args) != 2:
16+
raise SystemExit('Usage: %s portfoliofile' % args[0])
17+
filename = args[1]
18+
print('Total cost:', portfolio_cost(filename))
19+
20+
if __name__ == '__main__':
21+
main(sys.argv)
22+
23+
24+
25+
26+
27+
28+
29+
30+
31+
32+
33+
34+
35+
36+
37+
38+
39+
40+
41+
42+
43+
44+
45+
46+
47+
48+
49+
1350

14-
if len(sys.argv) == 2:
15-
filename = sys.argv[1]
16-
else:
17-
filename = input("Enter a filename: ")
1851

19-
cost = portfolio_cost(filename)
20-
print(f"Total cost: {cost}")

Work/report.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,13 @@ def portfolio_report(portfoliofile, pricefile):
3636
report = make_report(portfolio, prices)
3737
print_report(report)
3838

39-
portfolio_report('Data/portfoliodate.csv', 'Data/prices.csv')
39+
#portfolio_report('Data/portfoliodate.csv', 'Data/prices.csv)
40+
41+
def main(args):
42+
if len(args) != 3:
43+
raise SystemExit("Usage: %s portfile pricefile" % args[0])
44+
portfolio_report(args[1], args[2])
45+
46+
if __name__ == "__main__":
47+
import sys
48+
main(sys.argv)

0 commit comments

Comments
 (0)