Question: Python: Exceptions Handling! -- Write a program that will only accept input from a file provided as the first command line argument. If no file

Python: Exceptions Handling!

-- Write a program that will only accept input from a file provided as the first command line argument. If no file is given or the file cannot be opened, simply print Error opening file! and stop executing.

-- A valid input file should contain two lines. The first line is valid if it contains at least 2 characters ( may be one of these characters), The second line should contain a single integer.

-- The program should then print a single character from the string provided as the first line of input which is at the index given in the second line.

-- If this can't be done for any reason, the program should simply print Error reading input! and stop executing.

(To complete your solution you may use any combination of If-Then statements and Try-Except statements to either prevent exceptions from occurring or catching them when they do occur. Either approach is valid.)

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Here are examples of the expected input for the program and there correct output:

-Input- Testing123 7 -Output- 1 -------------------------------------------------------------------------------------------------------- -Input- abcd 75 -Output- Error reading input!

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!