We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 03a4251 commit 1fe5cadCopy full SHA for 1fe5cad
maths/trailing_zeroes.py
@@ -0,0 +1,40 @@
1
+"""
2
+ https://en.wikipedia.org/wiki/Trailing_zero
3
4
+
5
6
+def trailing_zeroes(num: int) -> int:
7
+ """
8
+ Finding the Trailing Zeroes i.e. zeroes present at the end of number
9
+ Args:
10
+ num: A integer.
11
+ Returns:
12
+ No. of zeroes in the end of an integer.
13
14
+ >>> trailing_zeroes(1000)
15
+ 3
16
+ >>> trailing_zeroes(102983100000)
17
+ 5
18
+ >>> trailing_zeroes(0)
19
+ 1
20
+ >>> trailing_zeroes(913273)
21
+ 0
22
23
+ ans = 0
24
+ if num < 0:
25
+ return -1
26
+ if num == 0:
27
+ return 1
28
+ while num > 0:
29
+ if num % 10 == 0:
30
+ ans += 1
31
+ else:
32
+ break
33
+ num /= 10
34
+ return ans
35
36
37
+if __name__ == "__main__":
38
+ import doctest
39
40
+ doctest.testmod()
0 commit comments