Question: Write a Python program to read a filename lines.py and displays the contents of the file with line number. For example, if the file contains:
Write a Python program to read a filename lines.py and displays the contents of the file with line number. For example, if the file contains:
''' This is line 1 This is line 2 This is line 3 '''
Then the program output is:
1: ''' 2: This is line 1 3: This is line 2 4: This is line 3 5: '''
Note, the lines.py file is provided. Use the lines.py input file. The output looks exactly like the input file contents except for the added line number and colon. Follow the example output.
Hint: Watch out for the blank line.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
