Question
Fill in the `write_first_line_to_file()` that accepts two arguments. This should write only the first line of the file contents into the given output file. -
Fill in the `write_first_line_to_file()` that accepts two arguments. This should write only the first line of the file contents into the given output file.
- **Argument 1:** The contents of a file to be written
- **Argument 2:** The name of an output file.
def write_first_line_to_file(file_contents, output_filename):
""" Writes the first line of a string to a file.
[IMPLEMENT ME]
1. Get the first line of file_contents
2. Use the File write() function to write the first line into a file
with the name from output_filename
We determine the first line to be everything in a string before the
first newline (' ') character.
Args:
file_contents: string to be split and written into output file
output_filename: the name of the file to be written to
"""
### 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.
Complete the `read_even_numbered_lines()` to return a list of the even-numbered lines of a file (2, 4, 6, etc.)
def read_even_numbered_lines(file_name):
""" Reads in the even numbered lines of a file
[IMPLEMENT ME]
1. Open and read the given file into a variable
2. Read the file line-by-line and add the even-numbered lines to a list
3. Return the list
Args:
file_name: the name of the file to be read
Returns:
list: a list of the even-numbered lines of the file
"""
### WRITE SOLUTION HERE
raise NotImplementedError()
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