[ Index | Exercise 1.2 | Exercise 1.4 ]
Objectives:
- Review basic file I/O
Files Created: pcost.py
The file Data/portfolio.dat
contains a list of lines with information
on a portfolio of stocks. The file looks like this:
AA 100 32.20
IBM 50 91.10
CAT 150 83.44
MSFT 200 51.23
GE 95 40.37
MSFT 50 65.10
IBM 100 70.44
The first column is the stock name, the second column is the number of shares, and the third column is the purchase price of a single share.
Write a program called pcost.py
that opens this file, reads
all lines, and calculates how much it cost to purchase all of the shares
in the portfolio. To do this, compute the sum of the second column
multiplied by the third column.
[ Solution | Index | Exercise 1.2 | Exercise 1.4 ]
>>>
Advanced Python Mastery
...
A course by dabeaz
...
Copyright 2007-2023
. This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License