diff --git a/sum_of_digits_of_a_number.py b/sum_of_digits_of_a_number.py index 64d62b281b7..f17fd6bcf41 100644 --- a/sum_of_digits_of_a_number.py +++ b/sum_of_digits_of_a_number.py @@ -13,6 +13,8 @@ 0 >>> sum_of_digits(999) 27 + >>> sum_of_digits(-123) + 6 """ import sys @@ -49,8 +51,8 @@ def sum_of_digits(n: int) -> int: Compute the sum of the digits of an integer. Args: - n:Non-negative integer - If the integer is negative , it is converted to postive interger and assigned to same number + n: Non-negative integer. + If the integer is negative, it is converted to positive before computing the sum. Returns: Sum of digits of the number. @@ -60,8 +62,10 @@ def sum_of_digits(n: int) -> int: 6 >>> sum_of_digits(405) 9 + >>> sum_of_digits(-789) + 24 """ - n=abs(n) + n = abs(n) # FIX: handle negative numbers total = 0 while n > 0: # Add last digit and remove it from n