Question
Note that this function does not want you to return the contents of the file; it just wants you to return the number of lines.
Note that this function does not want you to return the contents of the file; it just wants you to return the number of lines. The easiest way to do this function is to put the file in a for-loop and use an accumulator to count the number of times the body of the loop was executed.
I am not sure why my function is incorrect. I set up my accumulator can someone help and fix my code?
def count_lines(filepath): """ Returns the number of lines in the given file. Lines are separated by the ' ' character, which is standard for Unix files. Parameter filepath: The file to be read Precondition: filepath is a string with the FULL PATH to a text file """ # HINT: Remember, you can use a file in a for-loop accumulator = 0 for line in filepath: if line == ' ': accumulator = accumulator + 1
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