Question: 4. Write a fragment of code that counts the number of words in each line of an input le. Ir Declare and open the le

4. Write a fragment of code that counts the number of words in each line of an input le. Ir Declare and open the le (\"song . txt") I Declare an}.r other variables you need to accomplish this task Ir Displayr the line number and the number of words on that line II Close the le. Example lithe input le contains the following text: Row, row, row your boat, Gently down the stream. Merrily, merrily, merrily, merrily, life is but a dream. The output is: line 1: 5 words line 2: words line 3: words line : 5 words
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
