From 0ae387a8f433defc4af797692b7d1d247ce446ec Mon Sep 17 00:00:00 2001 From: uvok Date: Sun, 13 Apr 2025 15:29:56 +0200 Subject: Better exception --- bla.py | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'bla.py') diff --git a/bla.py b/bla.py index c73c234..d6fbecc 100644 --- a/bla.py +++ b/bla.py @@ -11,7 +11,10 @@ class FIFOQueue: def remove(self, amount): remaining = amount cost_basis = 0 + while remaining > 0: + if not self.queue: + raise ValueError(f"Insufficient assets in queue to process sale of {amount}.") quantity, price = self.queue[0] if quantity > remaining: cost_basis += remaining * price @@ -21,6 +24,7 @@ class FIFOQueue: cost_basis += quantity * price remaining -= quantity self.queue.popleft() + return cost_basis def process_ledger(file_path): -- cgit v1.2.3