From 22fe9fc96f1eb582838350244a163a6bc421157a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Kn=C3=BCttel?= Date: Wed, 14 Nov 2018 14:48:08 +0100 Subject: [PATCH] added Exercise 14 --- ex_14.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 ex_14.py diff --git a/ex_14.py b/ex_14.py new file mode 100644 index 0000000..5810721 --- /dev/null +++ b/ex_14.py @@ -0,0 +1,18 @@ +from util.io import readvalue + + +def fibonacci(n): + if(n in (0,1)): + return 1 + return fibonacci(n - 1) + fibonacci(n - 2) + +if( __name__ == "__main__"): + + def nonnegative_int(s): + i = int(s) + if(i < 0): + raise ValueError("{} is smaller than zero".format(i)) + return i + + n = readvalue("n > ", nonnegative_int) + print("fibonacci(", n, ") = ", fibonacci(n))