0% found this document useful (0 votes)
4 views

python pra16

The document contains two Python programming exercises. The first program checks for a ZeroDivisionError exception when dividing two numbers, while the second program defines a custom exception to validate a user's password. Both programs include error handling and user input functionality.

Uploaded by

birhadepranusha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

python pra16

The document contains two Python programming exercises. The first program checks for a ZeroDivisionError exception when dividing two numbers, while the second program defines a custom exception to validate a user's password. Both programs include error handling and user input functionality.

Uploaded by

birhadepranusha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Gramin Technical and Management Campus

Department of computer engineering


Subject/code: -Python/22616

Name:-Pranusha Shiddhodhan Birhade

DOP: DOS:-

Practical no 16
1) Write a Python program to Check for ZeroDivisionError Exception

Code:-
def divide_numbers(num1, num2):

try:

result = num1 / num2

except ZeroDivisionError:

print("Error: Division by zero is not allowed.")

return None

else:

return result

if __name__ == "__main__":

try:

numerator = float(input("Enter the numerator: "))

denominator = float(input("Enter the denominator: "))

division_result = divide_numbers(numerator, denominator)

if division_result is not None:

print(f"The result of {numerator} divided by {denominator} is: {division_result}")

except ValueError:

print("Invalid input. Please enter numeric values.")


Output:-

2) Write a Python program to create user defined exception that will


check whether the password is correct or not?

Code:-
class PasswordError(Exception):

pass

def check_password(input_password, correct_password):

if input_password != correct_password:

raise PasswordError("Incorrect password! Please try again.")

if __name__ == "__main__":

correct_password = "SecurePassword123"

user_password = input("Enter your password: ")

try:

check_password(user_password, correct_password)

print("Password is correct!")

except PasswordError as e:

print(e)
Output:-

You might also like