+ 1
Help!!!
The given program calculates and outputs the number of digits in a given number using a while loop. n = int(input()) length = 0 while n > 0: n //= 10 length += 1 print(length) PY During each iteration, the loop uses floor division to divide the given number by 10, thus dropping one digit. The process continues until the number has no more digits (n>0). You need to change the code to calculate and output the sum of all digits of the input number.
1 Antwort
+ 2
J1mbo Show
Another hint
You will need another variable to catch the result.
result = 0
Then as you get the remainder from each % iteration, you could add it to the result using +=