Python program to compute sum of digits in number


Topic: Python program to compute sum of digits in number

Solution

def sumDigits(no):  
    return 0 if no == 0 else int(no % 10) + sumDigits(int(no / 10))   
n = 1234511
print(sumDigits(n))



List all Python Programs