Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Uncategorized category for Sum of Digits by Sung_Woo_Jung
def sum_digits(num: int) -> int:
if num < 10:
return num
else:
total = num
list_num = []
while total >= 10:
for x in str(total):
list_num.append(int(x))
total = sum(list_num)
print(total)
list_num = []
return total
print("Example:")
print(sum_digits(38))
# These "asserts" are used for self-checking
assert sum_digits(38) == 2
assert sum_digits(0) == 0
assert sum_digits(10) == 1
assert sum_digits(132) == 6
assert sum_digits(232) == 7
assert sum_digits(811) == 1
assert sum_digits(702) == 9
print("The mission is done! Click 'Check Solution' to earn rewards!")
Dec. 6, 2024
Comments: