Question
Write a function called countWords() that accepts a filename and an integer representing the number of lines. e.g. countWords('raven.txt', 20). In this case, your function
Write a function called countWords() that accepts a filename and an integer representing the number of lines. e.g. countWords('raven.txt', 20).
In this case, your function should print the number of words in the first 20 lines of raven.txt
There should be a tab between the colon and the number of words. You must use a format string in your code.
Example:
countWords('raven.txt',10)
would output:
Line #1: 11 words
Line #2: 10 wordsLine #3: 10 wordsLine #4: 11 wordsLine #5: 11 wordsLine #6: 5 wordsLine #7: 0 wordsLine #8: 10 wordsLine #9: 11 wordsLine #10: 12 words
To keep things a bit simpler, you may assume that the second argument to the function will not ask for too many lines. For example, we will assume the user does not invoke: countWords('raven.txt',400000)
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