From 075644011aadf8e6915d52f214089524b81022f2 Mon Sep 17 00:00:00 2001 From: Bastian Date: Wed, 8 Jan 2020 12:45:39 +0000 Subject: [PATCH] initial commit --- factorial.py | 6 ++++++ fibonacci.py | 12 ++++++++++++ 2 files changed, 18 insertions(+) create mode 100644 factorial.py create mode 100644 fibonacci.py diff --git a/factorial.py b/factorial.py new file mode 100644 index 0000000..082af94 --- /dev/null +++ b/factorial.py @@ -0,0 +1,6 @@ +def factorial(num): + if not ((num >= 0) and (num % 1 == 0)): + raise Exception("Number can't be floating point or negative.") + return 1 if num == 0 else num * factorial(num - 1) + +print(factorial(6)) diff --git a/fibonacci.py b/fibonacci.py new file mode 100644 index 0000000..a491a84 --- /dev/null +++ b/fibonacci.py @@ -0,0 +1,12 @@ +def fibonacci(n): + if n <= 0: + return [0] + + sequence = [0, 1] + while len(sequence) <= n: + next_value = sequence[len(sequence) - 1] + sequence[len(sequence) - 2] + sequence.append(next_value) + + return sequence + +print(fibonacci(7))