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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!