Write a Python program to Check for ZeroDivisionError Exception.
division.py
num1=int(input("Enter a numerator: "))
num2=int(input("Enter a denominator: "))
try:
result=num1/num2
print("Division is: ",result)
except ZeroDivisionError:
print("Denominator can not be zero")
Output
Question 2
Write a Python program to create user defined exception that will check whether the password is correct or not?
password.py
class PasswordError(Exception):
pass
psw=input("Enter your password: ")
try:
if(psw!="Admin"):
raise PasswordError
else:
print("Password is correct")
except PasswordError:
print("Incorrect password entered")