Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

This will create a file named \"fibonacci.out\" in the same folder where your pr

ID: 3679517 • Letter: T

Question

This will create a file named "fibonacci.out" in the same folder where your program is running, with the following content:

1,2,3,4,5


The Fibonacci sequence was named after an Italian mathematician, considering the growth of bunny populations, and constituting the following numbers: 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144,. To compute a term n in the sequence, we use the following formula: F(n) = F(n-1) + F(n-2); so for example, F(3) = 1 + 1-2, and F(10)-21 + 34 = 55. Write a program to compute the entire Fibonacci sequence up to F(25) using a Python list data structure to store all the terms of the sequence. Finally, print out all the terms of the sequence to a file. Name your output file "fibonacci.out"

Explanation / Answer

Here , myList will have the 25 fibnocci numbers

-----------------------------

T1 = 1
T2 = 1
myList = [T1,T2]
for i in range(23):
T3 = T1 + T2
T1 = T2
T2 = T3
myList.append(T3)

print myList

------------------------------------------------------

complete program would be :

---------------------------------------------------

def writeList( fileName, theList ):
    f = open( fileName, "w" ) # open file for writing
    f.write( str( theList[0] ) ) # write the first element of the list
    for i in range( 1, len( theList ) ):
        f.write( "," ) # write a comma to separate the elements
        f.write( str( theList[i] ) ) # write the next element from the list
    f.write( " " ) #writes a "new line" at the end
    f.close() # close and save the file

T1 = 1
T2 = 1
myList = [T1,T2]
for i in range(23):
T3 = T1 + T2
T1 = T2
T2 = T3
myList.append(T3)
writeList("fibonacci.out", myList)

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote