Answers for "find the sum of digits in a number in python"

3

python sum of digits

def sum_digits(n):
    s = 0
    while n:
        s += n % 10
        n //= 10
    return s
Posted by: Guest on August-30-2020
0

sum of numbers in python

def sum_(n):
    if n == 0:
        return n
    else:
        prev_n = sum_(n - 1)
        result = prev_n + n
        return result


s = sum_(5)

print(s)

#Output:
# 15
Posted by: Guest on August-21-2021

Code answers related to "find the sum of digits in a number in python"

Python Answers by Framework

Browse Popular Code Answers by Language