Please y'all should help explain this code, i don't understand it | Sololearn: Learn to code for FREE!
Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren
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)

20th Jan 2021, 4:50 PM
NWACHUKWU PRECIOUS CALEB
NWACHUKWU PRECIOUS CALEB - avatar
2 Antworten
+ 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
20th Jan 2021, 4:55 PM
Slick
Slick - avatar
+ 2
Another example: 1234 // 10 = 123 123 // 10 = 12 12 // 10 = 1 1 // 10 = 0 1234 has 4 digits.
20th Jan 2021, 5:26 PM
noteve
noteve - avatar