Exercise 1.6 - Solution

# pcost.py

total_cost = 0.0

f = open('Data/portfolio.csv', 'r')
headers = next(f)
for line in f:
    row  = line.split(',')
    nshares = int(row[1])
    price = float(row[2])
    total_cost += nshares * price
f.close()

print 'Total cost', total_cost

[ Back ]