Skip to content

7 #19

Description

@legend17-dot

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.")

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions