Python 27.2 Summing Digits
Hello! I'm trying to find out how to do this practice (ID 27.2). I've tried many ways but I can't seem to understand how to do this one. The question is: this given program calculated and outputs the number of digits in a given number using a while loop. During each interaction, the loop used floor division to divide the given number by 10, thus dropping one digit. The process continues until th num et has no more digit (n>0) Sample input 643 Sample output 13 You need to change the code to calculate and output the sum of all digits of the input number” The code it gives you is: n = int(input()) length = 0 while n > 0: n //= 10 length += 1 print(length) I tried to do this, amongst other attempts, but I can’t seem to figure out how to get the result it wants. length = 0 while n > 0: n //= 10 d = int(n) total = sum(d %10) print(total) length += 1 print(length)