|
2 | 2 | "cells": [ |
3 | 3 | { |
4 | 4 | "cell_type": "code", |
5 | | - "execution_count": null, |
| 5 | + "execution_count": 2, |
6 | 6 | "metadata": {}, |
7 | | - "outputs": [], |
| 7 | + "outputs": [ |
| 8 | + { |
| 9 | + "name": "stdout", |
| 10 | + "output_type": "stream", |
| 11 | + "text": [ |
| 12 | + "Fibonacci Number is 5702887\n" |
| 13 | + ] |
| 14 | + } |
| 15 | + ], |
8 | 16 | "source": [ |
9 | 17 | "def fib(n, lookup): \n", |
10 | 18 | " \n", |
11 | | - " # Base case \n", |
12 | 19 | " if n == 0 or n == 1 : \n", |
13 | 20 | " lookup[n] = n \n", |
14 | | - " \n", |
15 | | - " # If the value is not calculated previously then calculate it \n", |
16 | 21 | " if lookup[n] is None: \n", |
17 | 22 | " lookup[n] = fib(n-1 , lookup) + fib(n-2 , lookup) \n", |
18 | 23 | " \n", |
19 | | - " # return the value corresponding to that value of n \n", |
20 | 24 | " return lookup[n] \n", |
21 | | - "# end of function \n", |
22 | | - " \n", |
23 | | - "# Driver program to test the above function \n", |
24 | 25 | "def main(): \n", |
25 | 26 | " n = 34 \n", |
26 | | - " # Declaration of lookup table \n", |
27 | | - " # Handles till n = 100 \n", |
28 | 27 | " lookup = [None]*(101) \n", |
29 | | - " print \"Fibonacci Number is \", fib(n, lookup) \n", |
| 28 | + " print(\"Fibonacci Number is \", fib(n, lookup))\n", |
30 | 29 | " \n", |
31 | 30 | "if __name__==\"__main__\": \n", |
32 | 31 | " main() " |
|
0 commit comments