Thanks to visit codestin.com Credit goes to github.com
We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 72dcfd9 commit b199039Copy full SHA for b199039
Work/pcost.py
@@ -1,3 +1,17 @@
1
# pcost.py
2
#
3
# Exercise 1.27
4
+
5
+# Initialise total to R0.0
6
+total_amount = 0.0
7
+with open('Data/portfolio.csv', 'rt') as file:
8
+ # Discard the titles
9
+ headers = next(file)
10
+ # Iterate over the stocks and sum all
11
+ for line in file:
12
+ stock_line = line.split(sep=',')
13
+ shares = int(stock_line[1])
14
+ price = float(stock_line[2])
15
+ total_amount += shares * price
16
17
+print(f'Total cost: R{total_amount:.2f}')
0 commit comments