Exception Handling - ArithmeticError

 # Exception handling 


N1 = eval(input("Enter number : "))

N2 = eval(input("Enter number : "))


try:

Res = N1/N2

except ArithmeticError as e:

print("ArithmeticError : ",e)

except:

print("Unknown error")

else:

print("Division = ",round(Res,4))

finally:

print("Exception handling complete.")

"""

Sample output

>python 11_EH2.py

Enter number : 4

Enter number : 5

Division =  0.8

Exception handling complete.


>python 11_EH2.py

Enter number : 4

Enter number : 's'

Unknown error

Exception handling complete.


>python 11_EH2.py

Enter number : 4

Enter number : 0

ArithmeticError :  division by zero

Exception handling complete.

"""

No comments:

Post a Comment

Don't be a silent reader...
Leave your comments...

Anu