added Exercise 14
This commit is contained in:
parent
f05ad4c580
commit
22fe9fc96f
18
ex_14.py
Normal file
18
ex_14.py
Normal 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))
|
Loading…
Reference in New Issue
Block a user