Initial commit

This commit is contained in:
David Beazley
2023-07-16 20:21:00 -05:00
parent 82e815fab2
commit 7d4b30154a
259 changed files with 600233 additions and 2 deletions

22
Solutions/1_6/pcost.py Normal file
View File

@@ -0,0 +1,22 @@
# pcost.py
def portfolio_cost(filename):
total_cost = 0.0
with open(filename) as f:
for line in f:
fields = line.split()
try:
nshares = int(fields[1])
price = float(fields[2])
total_cost = total_cost + nshares * price
# This catches errors in int() and float() conversions above
except ValueError as e:
print("Couldn't parse:", line)
print("Reason:", e)
return total_cost
if __name__ == '__main__':
print(portfolio_cost('../../Data/portfolio.dat'))