Write a Python program which have number (73421):
You should calculate (7 + 3 + 4 ….):
def sum_of_digits(n):
sum = 0
while n:
sum += n % 10
n //= 10
return sum
n = int(input('Enter a number: '))
s = sum_of_digits(n)
print('The sum of its digits is', s)
Comments
Leave a comment