Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed

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

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

Information Modeling And Relational Databases

Authors: Terry Halpin, Tony Morgan

2nd Edition

0123735688, 978-0123735683

Students also viewed these Databases questions