Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Object Databases The Essentials

Authors: Mary E. S. Loomis

1st Edition

020156341X, 978-0201563412

More Books

Students also viewed these Databases questions

Question

What do Dimensions represent in OLAP Cubes?

Answered: 1 week ago