Question
1. How to Complete the `read_file()` function to read in the sampletext.txt file using the `open` function and return the entire contents of the file.
1. How to Complete the `read_file()` function to read in the sampletext.txt file using the `open` function and return the entire contents of the file.
`read_file()` function:
def read_file(file_name):
""" Reads in a file.
[IMPLEMENT ME]
1. Open and read the given file into a variable using the File read()
function
2. Print the contents of the file
3. Return the contents of the file
Args:
file_name: the name of the file to be read
Returns:
string: contents of the given file.
"""
### WRITE SOLUTION HERE
raise NotImplementedError()
sampletext.txt:
Because I could not stop for Death, He kindly stopped for me; The carriage held but just ourselves And Immortality.
2. Complete the `read_file_into_line()` function so that it returns a data structure of all the contents of the file in a line-by-line sequential order.
def read_file_into_line(file_name):
""" Reads in a file and stores each line as an element in a list
[IMPLEMENT ME]
1. Open the given file
2. Read the file line by line and append each line to a list
3. Return the list
Args:
file_name: the name of the file to be read
Returns:
list: a list where each element is a line in the file.
"""
### WRITE SOLUTION HERE
raise NotImplementedError()
In Python Please!
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