Question
You need to create a Python list of length 25, populate it with the first 25 Fibonacci numbers, and then write that list to a
You need to create a Python \"list\" of length 25, populate it with the first 25 Fibonacci numbers, and then write that list to a file named \"fibonacci.out\".
Here is an example to show you how to write a list of numbers to a file. In particular, you can use the function \"writeList()\", given below, to do this:
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 You can use this function as follows: myList = [1,2,3,4,5] writeList(\"fibonacci.out\", myList)
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
Instead of '[1,2,3,4,5]', you have to create 'myList' to be a list of size 25, then fill out 'myList' with the first 25 Fibonacci numbers (by writing a Python program that manipulates 'myList', not by hand-coding the 25 numbers!), and then use 'writeList(\"fibonacci.out\", myList)' to write it to the file 'fibonacci.out'.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started