-3

How do I change the python code below to calculate and output the sum of all digits of the input number, based on the problem below?

n = int(input())
length = 0

while n > 0:
    n //= 10
    length += 1
    print(length)
TeddyBearSuicide
  • 1,377
  • 1
  • 6
  • 11

1 Answers1

0
n = input()
sum = 0

for char in n:
    if char.isdigit():
        sum += int(char)

print(sum)
TheEagle
  • 5,808
  • 3
  • 11
  • 39