Skip to content

Commit 8842cfb

Browse files
committed
Add partial solutions to the tasks
1 parent fc72ecd commit 8842cfb

1 file changed

Lines changed: 41 additions & 0 deletions

File tree

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
def sum_of_digits(n):
2+
result = 0
3+
4+
if n < 0:
5+
n = -1 * n
6+
7+
while n > 0:
8+
result += n % 10
9+
n = n // 10
10+
11+
return result
12+
13+
14+
def sum2_of_digits(n):
15+
n_str = str(n)
16+
if n_str[0] == '-':
17+
n_str = n_str[1::]
18+
19+
return sum([int(i) for i in n_str])
20+
21+
22+
def to_digits(digits):
23+
return list(map(int, list(str(digits))))
24+
25+
26+
def to_digits2(digits):
27+
return [int(i) for i in str(digits)]
28+
29+
30+
def to_number(digits):
31+
number_str = "".join([str(d) for d in digits])
32+
return int(number_str)
33+
34+
35+
# print(sum_of_digits(1325132435356))
36+
# print(sum2_of_digits(1325132435356))
37+
38+
# print(to_digits(123))
39+
# print(to_digits2(123))
40+
41+
print(to_number([21, 2, 33]))

0 commit comments

Comments
 (0)