From 129e74cbf4016e24c0583f883f8fa772e2a779a9 Mon Sep 17 00:00:00 2001 From: lolabird Date: Thu, 29 Feb 2024 15:24:04 -0700 Subject: [PATCH] Deal with negative cases --- thinkcspy/Chapter-16-Exercises/Problem9and10_gallons.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/thinkcspy/Chapter-16-Exercises/Problem9and10_gallons.py b/thinkcspy/Chapter-16-Exercises/Problem9and10_gallons.py index bb5653a..6f97986 100644 --- a/thinkcspy/Chapter-16-Exercises/Problem9and10_gallons.py +++ b/thinkcspy/Chapter-16-Exercises/Problem9and10_gallons.py @@ -8,6 +8,9 @@ def fillJug(rounds, jugA, jugB, target): if target > jugA["cap"]: print("Target is too high. Reducing target to Jug A's capacity.") target = jugA["cap"] + + if target < 0: + return if jugA["state"] == target: print("Target reached") @@ -37,7 +40,7 @@ def fillJug(rounds, jugA, jugB, target): def main(): jugA = {"name": "Jug A", "state": 0, "cap": 4} jugB = {"name": "Jug B", "state": 0, "cap": 3} - target = 2 + target = -5 return fillJug(1, jugA, jugB, target)