
def portfolio_cost(filename: str) -> float:
    with open(filename, 'r') as lines:
        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 = portfolio_cost(filename)
    print(f"value = {value}")
