Skip to content

Commit 4ba53a0

Browse files
committed
Use abs() to ensure possitive value
1 parent 8842cfb commit 4ba53a0

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

week01/01.PythonProblems/week1_solutions.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ def sum2_of_digits(n):
1919
return sum([int(i) for i in n_str])
2020

2121

22+
def sum3_of_digits(n):
23+
n_str = str(abs(n))
24+
return sum([int(i) for i in n_str])
25+
26+
2227
def to_digits(digits):
2328
return list(map(int, list(str(digits))))
2429

0 commit comments

Comments
 (0)