Problem 1 Write a function file_copy that takes two string parameters (in file and out_file) and copies the content of in file into out file. Assume that in_file exists before file_copy is called. For example, the following would be correct input and output: file_copy('created_equal.txt', 'copy.txt') >>> copy_f = open('copy.txt') >>> copy_f.read() 'We hold these truths to be self-evident,\nthat all men are created equal\n' Problem 2 Write a function named file_stats that takes one string parameter (in_file) that is the name of an existing text file. The function file_stats should calculate three statistics about in_file: the number of lines it contains, the number of words and the number of characters, and print the three statistics on separate lines. For example, the following would be correct input and output: >>> file_stats('created_equal.txt') lines 2 words 13 characters 72 Note: The number of characters may vary slightly between operating systems. Similarly, the number of lines may vary by 1 line, depending on the method used to calculate it. Problem 3 Write a function named repeat_words that takes two string parameters: 1. in file: the name of an input file that exists before repeat_words is called 2. out file: the name of an output file that repeat_words creates Assume that the input file is in the current working directory and write the output file to that directory. For each line of the input file, the function repeat_words should write to the output file all of the words that appear more than once on that line. Each word should be lower cased and stripped of leading and trailing punctuation. Each repeated word on a line should be written to the corresponding line of the output file only once, regardless of the number of times the word is repeated. For example, if the following is the content of the file catInTheHat.txt: Too wet to go out and too cold to play ball. So we sat in the house. We did nothing at all. So all we could do was to Sit! Sit! Sit! Sit! The following function call: inF='catInTheHat.txt' outF 'catRepWords.txt' repeat words(inF, outF) should create the file catRepWords.txt with the content: too to sit Hint: Be sure to test your solution with input in which some repeated words on a line are a mixture of upper and lower case, and in which repeated words sometimes are preceded or followed by punctuation.

C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter8: I/o Streams And Data Files
Section8.4: File Streams As Function Arguments
Problem 3E
icon
Related questions
Question
Using python editor IDLE, and if possible, when doing the problems, can you give the code solution in the most basic way to write it
Problem 1
Write a function file_copy that takes two string parameters (in file and
out_file) and copies the content of in file into out file. Assume that in_file
exists before file_copy is called. For example, the following would be
correct input and output:
file_copy('created_equal.txt', 'copy.txt')
>>> copy_f = open('copy.txt')
>>> copy_f.read()
'We hold these truths to be self-evident,\nthat all men are created equal\n'
Problem 2
Write a function named file_stats that takes one string parameter (in_file)
that is the name of an existing text file. The function file_stats should
calculate three statistics about in_file: the number of lines it contains, the
number of words and the number of characters, and print the three
statistics on separate lines. For example, the following would be correct
input and output:
>>> file_stats('created_equal.txt')
lines 2
words 13
characters 72
Note: The number of characters may vary slightly between operating
systems. Similarly, the number of lines may vary by 1 line, depending on
the method used to calculate it.
Problem 3
Write a function named repeat_words that takes two string parameters:
1. in file: the name of an input file that exists before repeat_words is called
2. out file: the name of an output file that repeat_words creates
Assume that the input file is in the current working directory and write the
output file to that directory.
For each line of the input file, the function repeat_words should write to
the output file all of the words that appear more than once on that line.
Each word should be lower cased and stripped of leading and trailing
punctuation. Each repeated word on a line should be written to the
corresponding line of the output file only once, regardless of the number
of times the word is repeated.
For example, if the following is the content of the file catInTheHat.txt:
Too wet to go out and too cold to play ball.
So we sat in the house.
We did nothing at all.
So all we could do was to Sit! Sit! Sit! Sit!
The following function call:
inF='catInTheHat.txt'
outF 'catRepWords.txt'
repeat words(inF, outF)
should create the file catRepWords.txt with the content:
too to
sit
Hint: Be sure to test your solution with input in which some repeated
words on a line are a mixture of upper and lower case, and in which
repeated words sometimes are preceded or followed by punctuation.
Transcribed Image Text:Problem 1 Write a function file_copy that takes two string parameters (in file and out_file) and copies the content of in file into out file. Assume that in_file exists before file_copy is called. For example, the following would be correct input and output: file_copy('created_equal.txt', 'copy.txt') >>> copy_f = open('copy.txt') >>> copy_f.read() 'We hold these truths to be self-evident,\nthat all men are created equal\n' Problem 2 Write a function named file_stats that takes one string parameter (in_file) that is the name of an existing text file. The function file_stats should calculate three statistics about in_file: the number of lines it contains, the number of words and the number of characters, and print the three statistics on separate lines. For example, the following would be correct input and output: >>> file_stats('created_equal.txt') lines 2 words 13 characters 72 Note: The number of characters may vary slightly between operating systems. Similarly, the number of lines may vary by 1 line, depending on the method used to calculate it. Problem 3 Write a function named repeat_words that takes two string parameters: 1. in file: the name of an input file that exists before repeat_words is called 2. out file: the name of an output file that repeat_words creates Assume that the input file is in the current working directory and write the output file to that directory. For each line of the input file, the function repeat_words should write to the output file all of the words that appear more than once on that line. Each word should be lower cased and stripped of leading and trailing punctuation. Each repeated word on a line should be written to the corresponding line of the output file only once, regardless of the number of times the word is repeated. For example, if the following is the content of the file catInTheHat.txt: Too wet to go out and too cold to play ball. So we sat in the house. We did nothing at all. So all we could do was to Sit! Sit! Sit! Sit! The following function call: inF='catInTheHat.txt' outF 'catRepWords.txt' repeat words(inF, outF) should create the file catRepWords.txt with the content: too to sit Hint: Be sure to test your solution with input in which some repeated words on a line are a mixture of upper and lower case, and in which repeated words sometimes are preceded or followed by punctuation.
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr