0
LOOPS
Guys I've been finding it really hard to understand this code. n = int(input()) length = 0 while n > 0: length += (n % 10) n //= 10 print(length)
4 Respuestas
+ 3
The code adds each digit of number <n> to <length>. For example, if <n> was 12345, then digit 5, 4, 3, 2, 1 (in that order) will be added to <length>.
+ 2
It will print the sum of the digits of the number
Like you say, 1234
It will give 1+2+3+4= 10
+ 2
Ex: input is 234
234>0 true
length = 0 +(234%10) = 0+4=4
n//=10 => 234//=10=> 23
23>0 true
length = 4 +(23%10) = 4+3=7
n//=10 => 23//=10 => 2
2>0 true
length = 7 +(2%10) = 7+2=9
n//=10 => 2//=10=> 0
0>0 false.
print(length) #9
0
Thanks for everything guys, solo won't be the same with y'all