File tree Expand file tree Collapse file tree 1 file changed +7
-3
lines changed
Expand file tree Collapse file tree 1 file changed +7
-3
lines changed Original file line number Diff line number Diff line change 1313 0
1414 >>> sum_of_digits(999)
1515 27
16+ >>> sum_of_digits(-123)
17+ 6
1618"""
1719
1820import sys
@@ -49,8 +51,8 @@ def sum_of_digits(n: int) -> int:
4951 Compute the sum of the digits of an integer.
5052
5153 Args:
52- n:Non-negative integer
53- If the integer is negative , it is converted to postive interger and assigned to same number
54+ n: Non-negative integer.
55+ If the integer is negative, it is converted to positive before computing the sum.
5456
5557 Returns:
5658 Sum of digits of the number.
@@ -60,8 +62,10 @@ def sum_of_digits(n: int) -> int:
6062 6
6163 >>> sum_of_digits(405)
6264 9
65+ >>> sum_of_digits(-789)
66+ 24
6367 """
64- n = abs (n )
68+ n = abs (n ) # FIX: handle negative numbers
6569 total = 0
6670 while n > 0 :
6771 # Add last digit and remove it from n
You can’t perform that action at this time.
0 commit comments