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)
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)
n = input()
sum = 0
for char in n:
if char.isdigit():
sum += int(char)
print(sum)