Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advances In Databases And Information Systems 14th East European Conference Adbis 2010 Novi Sad Serbia September 2010 Proceedings Lncs 6295

Authors: Barbara Catania ,Mirjana Ivanovic ,Bernhard Thalheim

2010th Edition

3642155758, 978-3642155758

More Books

Students also viewed these Databases questions

Question

Explain the importance of nonverbal messages.

Answered: 1 week ago