Skip to content

Commit 7b1fd14

Browse files
committed
csv files
1 parent 1d7707b commit 7b1fd14

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
@@ -13,11 +13,15 @@
1313
# Exercise 1.27
1414

1515

16-
with open('Data/portfolio.csv', 'rt') as file:
17-
header = next(file)
18-
total = 0
19-
for line in file:
20-
line2 = line.split(',')
21-
total += (int(line2[1])) * (float(line2[2]))
22-
print(total)
16+
def portfolio_cost(filename):
17+
with open(filename, 'rt') as file:
18+
header = next(file)
19+
total = 0
20+
for line in file:
21+
line2 = line.split(',')
22+
total += (int(line2[1])) * (float(line2[2]))
23+
return total
2324

25+
26+
cost = portfolio_cost('Data/portfolio.csv')
27+
print(cost)

0 commit comments

Comments
 (0)