From 1fe5cad5a37499cbfc0833bc948401f9daacdb81 Mon Sep 17 00:00:00 2001 From: Tejas Varshney Date: Tue, 15 Oct 2024 22:47:26 +0530 Subject: [PATCH 1/3] Added Trailing Zero Algo Created an algorithm that return the trailing zeroes of a number --- maths/trailing_zeroes.py | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 maths/trailing_zeroes.py diff --git a/maths/trailing_zeroes.py b/maths/trailing_zeroes.py new file mode 100644 index 000000000000..f0c7238ea48d --- /dev/null +++ b/maths/trailing_zeroes.py @@ -0,0 +1,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() From 266c203a49d45909830e7f8129f26036018bde93 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 15 Oct 2024 17:20:10 +0000 Subject: [PATCH 2/3] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- maths/trailing_zeroes.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/maths/trailing_zeroes.py b/maths/trailing_zeroes.py index f0c7238ea48d..b1c1cdea0bbf 100644 --- a/maths/trailing_zeroes.py +++ b/maths/trailing_zeroes.py @@ -1,5 +1,5 @@ """ - https://en.wikipedia.org/wiki/Trailing_zero +https://en.wikipedia.org/wiki/Trailing_zero """ From b464088c548ca9ed24110f1fc17308fe8d938843 Mon Sep 17 00:00:00 2001 From: cclauss Date: Tue, 8 Sep 2026 13:10:52 +0000 Subject: [PATCH 3/3] updating DIRECTORY.md --- DIRECTORY.md | 1 + 1 file changed, 1 insertion(+) diff --git a/DIRECTORY.md b/DIRECTORY.md index c5bac23ad35b..064844b94907 100644 --- a/DIRECTORY.md +++ b/DIRECTORY.md @@ -874,6 +874,7 @@ * [Test Factorial](maths/test_factorial.py) * [Test Prime Check](maths/test_prime_check.py) * [Three Sum](maths/three_sum.py) + * [Trailing Zeroes](maths/trailing_zeroes.py) * [Trapezoidal Rule](maths/trapezoidal_rule.py) * [Triplet Sum](maths/triplet_sum.py) * [Twin Prime](maths/twin_prime.py)