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