From e6a2adc1e05537ef8398618925583d7fe67ecd35 Mon Sep 17 00:00:00 2001 From: hovinh Date: Mon, 16 Oct 2017 21:56:35 +0800 Subject: [PATCH] update factorial for python3 (#238) --- factorial/Factorial.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 factorial/Factorial.py diff --git a/factorial/Factorial.py b/factorial/Factorial.py new file mode 100644 index 000000000..903228f73 --- /dev/null +++ b/factorial/Factorial.py @@ -0,0 +1,24 @@ +'''THIS VERSION IS FOR PYTHON3''' +result = [i for i in range(1000)] + +def fact_dp(n): + result[0] = 1 + end = min(n, 1000) + 1 + for i in range(1, end): + result[i] = i * result[i - 1] + + return result[n] + +if __name__ == '__main__': + + n = None + + try: + n = int(input("Enter a number :")) + except ValueError: + print ("Not a number") + + if (n <= 0): + print (1) + else: + print ("Factorial : ", fact_dp(n))