Question: Write a program that asks the user for the name of a file. The program should read all of the files data into a list

Write a program that asks the user for the name of a file. The program should read all of the file’s data into a list and display the number of lines of data that the file contains, and then ask the user to enter the number of the line that they want to view. The program should display the specified line.

The program should handle the following exceptions by displaying an error message:

• IOError exceptions that are raised when the specified filename cannot be found or opened.

• ValueError exceptions that are raised when a non-integer value is given as a line number.

• IndexError exceptions that are raised when the line number is outside the range of the data list.

Step by Step Solution

3.42 Rating (152 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

ANSWER python def readfiledata filename inputEnter the name of the file try with openfilename r as ... View full answer

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 Starting Out With Python Questions!