From fa9d0449dd92ca71f314a224b392f8f360892773 Mon Sep 17 00:00:00 2001 From: SEMIRATESFAI Date: Sat, 11 Jan 2025 23:23:46 -0500 Subject: [PATCH] Update sum_of_digits.py Replace the assert statement with an explicit if statement and raise a ValueError in the sum_of_digits function --- solutions/challenge_9/sum_of_digits.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/solutions/challenge_9/sum_of_digits.py b/solutions/challenge_9/sum_of_digits.py index 587c53d13..97849b4e6 100644 --- a/solutions/challenge_9/sum_of_digits.py +++ b/solutions/challenge_9/sum_of_digits.py @@ -38,5 +38,7 @@ def sum_of_digits(n: int) -> int: >>> sum_of_digits(0) 0 """ - assert isinstance(n, int) and n >= 0, "input must be a positive integer" + if not isinstance(n, int) or n < 0: + raise ValueError("input must be a positive integer") + return sum(int(digit) for digit in str(n))