This commit is contained in:
Mike Bloy 2023-08-11 11:24:47 -05:00
parent 784349ec36
commit 73cbc2de2a

View File

@ -1,17 +1,19 @@
from decimal import Decimal
def run(filename: str) -> Decimal:
def portfolio_cost(filename: str) -> float:
with open(filename, 'r') as lines:
total = Decimal(0.0)
_, count, price = lines.readline().split()
count = Decimal(count)
price = Decimal(price)
total += count * price
total = 0.0
for line in lines:
_, count, price = line.split()
try:
count = int(count)
price = float(price)
total += count * price
except ValueError as ex:
print(f"Couldn't parse {line!r}. Reason: {ex!r}")
return total
if __name__ == '__main__':
filename = 'Data/portfolio.dat'
value = run(filename)
value = portfolio_cost(filename)
print(f"value = {value}")