Skip to content

Commit 49b10d8

Browse files
committed
Exercise 1.30
1 parent 12abd88 commit 49b10d8

1 file changed

Lines changed: 11 additions & 7 deletions

File tree

‎Work/pcost.py‎

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,16 @@
22
#
33
# Exercise 1.27
44

5-
total_cost = 0
5+
def portfolio_cost(filename):
6+
total_cost = 0
67

7-
with open('Data/portfolio.csv', 'rt') as f:
8-
headers = next(f)
9-
for line in f:
10-
row = line.split(',')
11-
total_cost = total_cost + int(row[1]) * float(row[2])
8+
with open(filename, 'rt') as f:
9+
headers = next(f)
10+
for line in f:
11+
row = line.split(',')
12+
total_cost = total_cost + int(row[1]) * float(row[2])
13+
return total_cost
14+
15+
cost = portfolio_cost('Data/portfolio.csv')
16+
print('Total cost:', cost)
1217

13-
print(f'Total cost {total_cost:0.2f}')

0 commit comments

Comments
 (0)