Answered step by step
Verified Expert Solution
Link Copied!

Question

00
1 Approved Answer

1. Lets start with the program from the try_except lecture (slide 22). Create a py file (Q1_custom_Except), type in the program, run, and test it

1. Lets start with the program from the try_except lecture (slide 22). Create a py file (Q1_custom_Except), type in the program, run, and test it by entering a negative number. You should see the following results for inputs of a, -9, and 8: ''' ~ results Enter number: a NAN ...... Enter number: -9 less the zero ....... Enter number: 8 ''' We want to modify the program to give us informative error messages instead of less than zero. We want to use the object from the LessThanZeroError(Exception) class to display the actual value of my_num. In addition, we want to show the else case when the number is > zero and a finally to display done. ''' ~ results: Enter number: a your Entered number is: NAN Done ...... Enter number: -9 You entered my_num: -9, it must be greater than 0 ! Done ..... Enter number: 8 entered value is 8 Done ''' a. Create an object (e1 = LessThanZeroError(my_num) after the if my_num < 0: (around line 11) b. Modify the raise LessThanZeroError(arguments) to display the entered value and updated message c. Modify the except LessThanZeroError (around line 17) to include a variable ex to capture and display the raised message (from around line 14) d. Add the else and finally statements to display the no exception message and wrap up (done) messages.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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

Students also viewed these Databases questions