From 88ab2025bed612e31a2097fefedbed11722a3cfd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cem=20Ba=C4=9Flum?= <39911281+cembglm@users.noreply.github.com> Date: Thu, 6 Jan 2022 00:06:26 +0300 Subject: [PATCH] enh(Python): rename function's name to factorial_nonrecursion (#662) --- algorithms/Python/recursion/factorial.py | 37 +++++++++++++----------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/algorithms/Python/recursion/factorial.py b/algorithms/Python/recursion/factorial.py index f7e85d88..16b89e68 100644 --- a/algorithms/Python/recursion/factorial.py +++ b/algorithms/Python/recursion/factorial.py @@ -1,19 +1,21 @@ -def FactorialNonRecursion(number): +""" This is the update of factorial.py to provide standard of the clean codes.""" + +def factorial_nonrecursion(number): """ - >>> FactorialNonRecursion(3) + >>> factorial_nonrecursion(3) 6 - >>> FactorialNonRecursion(5) + >>> factorial_nonrecursion(5) 120 - >>> FactorialNonRecursion(0) + >>> factorial_nonrecursion(0) 1 - >>> FactorialNonRecursion(1) + >>> factorial_nonrecursion(1) 1 """ if isinstance(number, float): raise ValueError("Non integer number is not allowed") if number < 0: raise ValueError("Negative number is not allowed") # Raise an error here - if number == 0 or number == 1: + if number in {0,1}: return 1 result = 1 @@ -21,32 +23,33 @@ def FactorialNonRecursion(number): result = result * i return result -def FactorialRecursion(number): +def factorial_recursion(number): """ - >>> FactorialRecursion(3) + >>> factorial_recursion(3) 6 - >>> FactorialRecursion(5) + >>> factorial_recursion(5) 120 - >>> FactorialRecursion(0) + >>> factorial_recursion(0) 1 - >>> FactorialRecursion(1) + >>> factorial_recursion(1) 1 """ if isinstance(number, float) is True: raise ValueError("Non integer number is not allowed") if number < 0: raise ValueError("Negative number is not allowed") - if number == 0 or number == 1: + if number in {0,1}: return 1 - return number * FactorialRecursion(number-1) + return number * factorial_recursion(number-1) def main(): - testFactorial = FactorialNonRecursion(5) - print(testFactorial) + """ main function for factorial """ + test_factorial = factorial_nonrecursion(5) + print(test_factorial) - testRecursion = FactorialRecursion(4) - print(testRecursion) + test_recursion = factorial_recursion(4) + print(test_recursion) if __name__ == "__main__": main()