Question: Write a Python function showlines( filepath ) that displays the line numbers at the beginning of each line followed by the content of that line.

Write a Python function showlines( filepath ) that displays the line numbers at the beginning of each line followed by the content of that line.

You must use your getnlines() function from Question 1 to first find out how many lines you have in your file.

Then you must format your line number printout according to how many digits you will need to display all line numbers.

Line numbers must start from 1.

For example, if filepath contains 345 lines, you will need 3 spaces to represent all line numbers. Then, for line numbers with less digits should be prefixed with zeros!

So, the call

showlines( filepath )

should print out the line numbers in the following format:

001 .... 002 .... ... .... 009 .... 010 .... ... .... 100 .... ... .... 340 .... 341 .... 342 .... 343 .... 344 .... 345 ....

Write test code, as you always should, that demonstrates your code works as expected.

Note that this question is similar to PROGRAMMING EXERCISE 7.2, but please answer the above question instead.

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!