Question: Write a PYTHON program that asks the user for the name of the file. The program should write the contents of this input file to

Write a PYTHON program that asks the user for the name of the file. The program should write the contents of this input file to an output file. In the output file, each line should be preceded with a line number followed by a colon. The output file will have the same name as the input filename, preceded by ln (for linenumbers). Be sure to use Try/except to catch all exceptions.

For example, when prompted, if the user specifies sampleprogram.py and that file contains:

#Jim Eddy #CS21

#Sample program print('This is a sample program')

print('Do you remember when this seemed hard?')

print('Python is Cool!')

Your program will produce the file named ln_sampleprogram.py and it will contain:

1: #Jim Eddy

2: #CS21

3: #Sample program

4: print('This is a sample program')

5: print('Do you remember when this seemed hard?')

6: print('Python is Cool!')

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!