From 69087f789e9baea3b239671fe82dab66623dab46 Mon Sep 17 00:00:00 2001 From: Fonta22 <61181201+Fonta22@users.noreply.github.com> Date: Sat, 28 Nov 2020 12:54:05 +0100 Subject: [PATCH] Added factorial in Python --- Maths/Factorial/factorial.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 Maths/Factorial/factorial.py diff --git a/Maths/Factorial/factorial.py b/Maths/Factorial/factorial.py new file mode 100644 index 0000000..249c7e7 --- /dev/null +++ b/Maths/Factorial/factorial.py @@ -0,0 +1,13 @@ +fc = 1 + +def factorial(num, fc): + if num < 0: + print("Can't calculate the factorial of a negative number :/") + elif num == 0: + print("0! = 1") + else: + for i in range(1, num + 1): + fc = fc * i + print(f"{num}! = {fc}") + +factorial(0, fc) # Number to make the factorial