0

n = int(input()) length = 0 while n > 0: n //= 10 length += 1 print(length)

can anyone explain this..?

17th Oct 2020, 2:46 AM
Rahul Prasad
Rahul Prasad - avatar
4 ответов
+ 3
It gets the digit of a number by division by 10. The reason of floor division is to get rid of the decimal. For example input 428 428 // 10 = 42 length = 1 42 // 10 = 4 length = 2 4 // 10 = 0 length = 3 0 > 0 is false, loop ends.
17th Oct 2020, 3:04 AM
你知道規則,我也是
你知道規則,我也是 - avatar
+ 3
Your code is simple first you taking number which type will be int and u take another variable length which will cout the length of Entered number . Your loop will run upto >0 times if condition will false then you will exit from loop In next line you wrote n//=10 if you will divide number by 10 it will seperate your number and length += 1 will count total number. if u will run of rough copy you can understood much better
17th Oct 2020, 3:06 AM
A S Raghuvanshi
A S Raghuvanshi - avatar
0
n=int(input(" enter:")) i = 0 while n>0: i += 1 n = n//10 print (i)
30th Aug 2023, 9:54 PM
Bardia
- 2
which interpreter can run this as is and produce result or without an error?
20th Jan 2021, 7:47 AM
Kostas_V