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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started