Skip to content

Commit

Permalink
Update sum_of_digits.py
Browse files Browse the repository at this point in the history
Replace the assert statement with an explicit if statement and raise a ValueError in the sum_of_digits function
  • Loading branch information
SEMIRATESFAI authored Jan 12, 2025
1 parent 76ba362 commit fa9d044
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion solutions/challenge_9/sum_of_digits.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))

0 comments on commit fa9d044

Please sign in to comment.