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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!