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)

31st Oct 2020, 8:48 AM
Japjot Singh Chauhan
Japjot Singh Chauhan - avatar
2 ответов
+ 9
#Try this n = int(input()) a = 0 length = 0 while n > 0: b= n%10 a+= b n//= 10 length += 1 print(a)
31st Oct 2020, 9:03 AM
Simba
Simba - avatar
+ 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.
31st Oct 2020, 9:02 AM
ChaoticDawg
ChaoticDawg - avatar