Files
Python/maths/trailing_zeroes.py
Tejas Varshneypre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>Christian Clausscclauss
de3df05a9c Added Trailing Zero Algo (#12104)
* Added Trailing Zero Algo

Created an algorithm that return the trailing zeroes of a number

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* updating DIRECTORY.md

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Christian Clauss <cclauss@me.com>
Co-authored-by: cclauss <cclauss@users.noreply.github.com>
2026-09-08 15:16:36 +02:00

41 lines
710 B
Python

"""
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()