Answer to Question #325051 in Python for Yola

Question #325051
Write a Python program which have number (73421):
 You should calculate (7 + 3 + 4 ….):




1
Expert's answer
2022-04-06T17:55:20-0400
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)

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS