Skip to main content

Program for performing some addition, sum, product and division operation on given input and handle all types of Exceptions using Attribute Error, Value Error and Division by Zero Error, etc

· One min read
Kaustubh Kulkarni

Que > Program for performing some addition, sum, product and division operation on given input and handle all types of Exceptions using Attribute Error, Value Error and Division by Zero Error, etc

file.py
try:
n1=int(input("Enter Integer 1:"))
n2=int(input("Enter Integer 2:"))
print(" N1 * N2 = ", n1*n2)
print(" N1 / N2 =",n1/n2)
print(" N1 + N2 =",n1+n2)
print(" N1 - N2 =",n1-n2)
except ValueError:
print("ValueError- Please enter valid number")
except ZeroDivisionError:
print("ZeroDivisionError: You can not divide number by 0")
except AttributeError:
print("AttributeError: Attribute is not valid")
except e as Exception:
print("Unhandled Exception Ocurred : ",e)
finally:
print("Program terminated")
Output
Enter Integer 1:6
Enter Integer 2:0
N1 * N2 = 0
ZeroDivisionError: You can not divide number by 0
Program terminated