From 7750143196754999dc8ffdef9654bf7c9340590e Mon Sep 17 00:00:00 2001 From: arnaugamez Date: Wed, 25 Oct 2017 20:07:25 +0200 Subject: [PATCH] Add recursive factorial function --- fact.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 fact.py diff --git a/fact.py b/fact.py new file mode 100644 index 0000000..a0a9cd9 --- /dev/null +++ b/fact.py @@ -0,0 +1,15 @@ +def fact(n): + + if n < 0: + return("Error, factorial function is not defined for negative values") + if n == 0: + return 1 + + return n*fact(n-1) + +try: + n = int(raw_input("Enter your number to factorize: ")) + print(fact(n)) + +except ValueError: + print("You must enter an integer number!")