Program to create user-defined exception that will check whether the password is correct or not? ((MSBTE Pratical Question))
Code:
class
ValidatePassword(Exception):
username = "Mhssp"
password = "Mhssp123"
def __init__(self, user, pas):
if (self.password == pas) and
(self.username == user):
print("Login
Successful!")
else:
print("Incorrect
Password!")
try:
user = input("Enter username: ")
pas = input("Enter password: ")
raise(ValidatePassword(user,pas))
except ValidatePassword
as error:
print("A new Exception occured!",
error)
Output:
Comments
Post a Comment