def DivExp(a, b):
Assertion for a > 0
assert a > 0, "Value of 'a' must be greater than 0"
Raise exception if b == 0
if b == 0:
raise ZeroDivisionError("Division by zero is not allowed")
c = a / b
return c
Main Program
try:
a = int(input("Enter value of a: "))
b = int(input("Enter value of b: "))
result = DivExp(a, b)
print("Result (c = a/b):", result)
except AssertionError as ae:
print("Assertion Error:", ae)
except ZeroDivisionError as zde:
print("Error:", zde)
except ValueError:
print("Invalid input! Please enter integers only.")
def DivExp(a, b):
Assertion for a > 0
assert a > 0, "Value of 'a' must be greater than 0"
Raise exception if b == 0
if b == 0:
raise ZeroDivisionError("Division by zero is not allowed")
c = a / b
return c
Main Program
try:
a = int(input("Enter value of a: "))
b = int(input("Enter value of b: "))
result = DivExp(a, b)
print("Result (c = a/b):", result)
except AssertionError as ae:
print("Assertion Error:", ae)
except ZeroDivisionError as zde:
print("Error:", zde)
except ValueError:
print("Invalid input! Please enter integers only.")