Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
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 numberStep 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