Question
(PYCHARM) Since the read operation in this case is going to read the file line-by-line into an array, you will need to use a loop
(PYCHARM)
Since the read operation in this case is going to read the file line-by-line into an array, you will need to use a loop to print it out. This is because each line in the file is read into each cell of the array. That is, the first line goes into arrayElement[0], the second line goes into arrayElement[1], and so on.
Lastly, when using a with iterator to read a file, you don't need to close it when your function is finished. The withiterator will automatically close the file when it reaches an EOF marker. EOF means end of file. Remember, an iterator is something that loops through data.
Create a Python program from the following pseudo-code:
Subprogram writeNameAssn() Write "My name is:" Write "This is assignment: " End Subprogram Subprogram saveData(fn, dataString) Open fn For Output As dataOut Write dataOut, dataString Close dataOut End Subprogram Subprogram getData(fn) Read all lines in fn into an array Close not required using with statement Return array End Subprogram Subprogram printData(a): Write each line in the array to the monitor End Subprogram Main Declare textIn as array Set fileName = "data.txt" Call saveData(fn, "This is a test") Set textin = getData(fileName) Call printData(textIn) End Main Execute Main
Python Interaction
My name is: David Brodersen This is assignment: P8 This is a test
data.txt file contents
This is a test
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