added Exercise 14

This commit is contained in:
Daniel Knüttel 2018-11-14 14:48:08 +01:00
parent f05ad4c580
commit 22fe9fc96f

18
ex_14.py Normal file
View File

@ -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))