Write a loop to build a LIST data structure that contains the first 5000 Fibonacci numbers. Just fill the list from left to right adding the two previous values. Why can we not use a recursive function here, or any other function for that matter?? Look up LIST and how to use .append() method on this object. Once this LIST is full you can read the numbers from the file by reading one line at a time. The read line is a string, it “122″ and must be converted to an int, such as k=int(line) . Index the LIST with k and print out the Fibonacci value. Look up how to open and read a line from the file. Just create a data file in the same directory with your script and put numbers in it to read.
The Fibonacci numbers [ 0,1, 1, 2, 3, 5, 8, 13, 21, 34, 55, ...]are defined by the recurrence:
fib[n]=fib[n-1]+fib[n-1] where fib=fib=1
Write a python program to calculate the nth Fibonacci Numbers.
Input and Output
The input to your program will be a file that contains a sequence of numbers (n) smaller or equal than 5000, each on a separate line, specifying which Fibonacci number to calculate. Your program should output the Fibonacci number for each input value, one per line using the given output format as shown below.
Here is the fibdata to run thru your program. Turn in a copy of the documented source and output stapled together. Include in your documentation you name at the top, name of program and a section explaining what the program does. Note: you can get the output to a file by saving to the history.log
5 7 11
The Fibonacci number for 5 is 5 The Fibonacci number for 7 is 13 The Fibonacci number for 11 is 89