From f69e82e66d032a0304b36dd9fa787a1d30e2732d Mon Sep 17 00:00:00 2001 From: Derderderr Date: Fri, 13 Feb 2026 00:03:07 +0800 Subject: [PATCH] Fix Multiply.py Add negative logic, otherwise infinite loop if b is negative --- Multiply.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Multiply.py b/Multiply.py index c8e1b52228f..d8d06ffd50a 100644 --- a/Multiply.py +++ b/Multiply.py @@ -1,4 +1,8 @@ def product(a, b): + # for negative vals, return the negative result of its positive eval + if b < 0: + return -product(a, -b) + if a < b: return product(b, a) elif b != 0: @@ -9,4 +13,4 @@ def product(a, b): a = int(input("Enter first number: ")) b = int(input("Enter second number: ")) -print("Product is: ", product(a, b)) +print("Product is:", product(a, b))