Count-Trailing-Zeros(x) --- Can I use Log(x) to see if X is equal to ( Integer * 10 ^ k) ???
Hen Hanna
henhanna at gmail.com
Sun Sep 18 11:49:37 EDT 2022
Count how many zeros are at the end of your int:
def end_zeros(num):
s = str(num)
return len(s) - len(s.rstrip("0"))
print(end_zeros(10)) # == 1
print(end_zeros(101)) # == 0
print(end_zeros(245)) # == 0
print(end_zeros(100100)) # == 2
---------------- Writing a loop (using % and // ) feels like [reinventing the wheel] and seems intrinsically wrong.
i like this code (above) because it's not reinventing the wheel --- the Python implementor has already done the loop (using % and // ), so i'm just using that efficient tool (routine).
More information about the Python-list
mailing list