21.3k views
3 votes
Write a program fragment that demonstrates how a DivideByZero exception can be handled at a scope higher than the code that generated the exception.

User Uthman
by
4.9k points

1 Answer

5 votes

Answer:

numerator = int(input("Enter integer number: "))

denum = int(input("Enter integer number: "))

try:

print(numerator/denum)

except ZeroDivisionError:

print("denuminator should not be zero.")

Step-by-step explanation:

Division with zero in mathematics results in infinity and for programming, it throws an error message. The exception handling in programming is used to bypass error messages and prevent code from crashing.

The python program above uses the 'try' and 'except' exception handling to get the division of the numerator and denum variables. The except statement print a message if the division should throw a ZeroDivisionError.

User MatteKarla
by
5.3k points