Examine the code: Code: 1 x=eval(input("Enter value for x: \n")) 2 y=eval(input("Enter value for y: \n")) 3 z=(x+y)/(x-y

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

Examine the code: Code: 1 x=eval(input("Enter value for x: \n")) 2 y=eval(input("Enter value for y: \n")) 3 z=(x+y)/(x-y

Post by answerhappygod »

Examine the code:Code:1x=eval(input("Enter value for x: \n"))2y=eval(input("Enter value for y: \n"))3z=(x+y)/(x-y)4print (z)When the program is tested with same value for x and y (for examplex=4 and y=4), it generates the following error and crashes.Traceback (most recent call last):....File "D:/xyz.py", line 3, in <module>z=(x+y)/(x-y)ZeroDivisionError: division by zeroCopy above code in your answer and insert lines where necessary forhandling the ZeroDivisionError error to save your program fromcrashing.
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply