0
Please y'all should help explain this code, i don't understand it
n = int(input()) length = 0 while n > 0: n //= 10 length += 1 print(length)
2 ответов
+ 4
it tells you the amount of digits in a number.
// is hard division (doesn't deal w/ remainders)
every time you // a number by 10, it takes a number off:
1000 // 10 = 100
100 // 10 = 10
10 // 10 = 1
1 // 10 = 0
There are 4 numbers in 1000
+ 2
Another example:
1234 // 10 = 123
123 // 10 = 12
12 // 10 = 1
1 // 10 = 0
1234 has 4 digits.