-
-
Notifications
You must be signed in to change notification settings - Fork 51.2k
Expand file tree
/
Copy pathtrailing_zeroes.py
More file actions
40 lines (34 loc) · 711 Bytes
/
Copy pathtrailing_zeroes.py
File metadata and controls
40 lines (34 loc) · 711 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
"""
https://en.wikipedia.org/wiki/Trailing_zero
"""
def trailing_zeroes(num: int) -> int:
"""
Finding the Trailing Zeroes i.e. zeroes present at the end of number
Args:
num: A integer.
Returns:
No. of zeroes in the end of an integer.
>>> trailing_zeroes(1000)
3
>>> trailing_zeroes(102983100000)
5
>>> trailing_zeroes(0)
1
>>> trailing_zeroes(913273)
0
"""
ans = 0
if num < 0:
return -1
if num == 0:
return 1
while num > 0:
if num % 10 == 0:
ans += 1
else:
break
num //= 10
return ans
if __name__ == "__main__":
import doctest
doctest.testmod()