Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Design Application And Administration

Authors: Michael Mannino, Michael V. Mannino

2nd Edition

0072880678, 9780072880670

More Books

Students also viewed these Databases questions