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
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)
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.