0
Will anybody please edit this code so it starts returning sum of values for ex-42 output-6
n = int(input()) length = 0 while n > 0: n //= 10 length += 1 print(length)
2 odpowiedzi
+ 9
#Try this
n = int(input())
a = 0
length = 0
while n > 0:
b= n%10
a+= b
n//= 10
length += 1
print(a)
+ 4
If you're asking to get the sum of the digits in a given number.
I.E. input is 42
4 + 2 = 6
output 6
Then here:
nums = map(int, list(input()))
total = 0
for num in nums:
total += num
print(total)
Otherwise, please explain a bit better what it is you're trying to do.