Question: Problem : Try / Except / Else Answer in Python. Use the code given in the answer and follow all instructions. Modify the below program

Problem : Try / Except / Else

Problem : Try / Except / Else Answer in Python. Use the

Answer in Python. Use the code given in the answer and follow all instructions.

Modify the below program to satisy the following requirements: When a ValueError is raised, the program will display this message: Not a number! When an AssertionError is raised, the program will display this message: Not an even number! When no exception is raised, the program will display the reciprocal of the number entered. Your program must include the following keywords: assert, try, except, else. . Note: A ValueError is raised when a user types in data of an inappropriate type. Note: An AssertionError is raised when a user types in numeric data that is not even. Note: Use the modulus operator, sometimes also called the remainder operator, to determine whether an input number is either even or odd. Note: Do not include in the assert statement a condition; instead, however, 'catch' the exception using except. Note: Additional references on Python's assert statement: https://stackoverflow.com/questions/5142418/what-is-the-use-of-assert-in-python In [1]: try: num = int(input("Enter an even number: ")) assert num% 2 == 0 except ValueError: Enter an even number: 9 Not an even number

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!