Question
Write a function named lineStats that finds the number of words and the number of characters on each line of a file and writes those
Write a function named lineStats that finds the number of words and the number of characters on each line of a file and writes those statistics to a corresponding line of a new file, separated by a space. (Hint: when you read a line from a file, the endline character is included. Do not include the endline in the number of characters on the line.)
The function lineStats takes two parameters:
1. infile, a string, the name of an input file that exists before lineStats is called
2. outfile, a string, the name of an output file that lineStats creates and writes to.
For example, if the following is the content of the file promisedLand.txt:
The dogs on main street howl,
'cause they understand,
And I believe in a promised land I believe in a promised land...
The following function call:
inF = 'promisedLand.txt'
outF = 'promisedLandStats.txt'
lineStats(inF, outF)
should create the file promisedLandStats.txt with the content:
6 29
3 23
0 0
7 32
6 31
Answer in Python
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