0% found this document useful (0 votes)
21 views1 page

Lab Program 5

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

Lab Program 5

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

5. Write a function named DivExp which takes TWO parameters a,b and returns a value c (c=a/b).

Write suitable assertion for a>0 in function DivExp and raise an exception for when b=0.Develop a
suitable program which reads two values from the console and calls a function DivExp.

def DivExp(a, b):

assert a > 0, "Assertion Error: a must be greater than 0"

if b == 0:

raise ZeroDivisionError("Error: Division by zero")

c=a/b

return c

a = float(input("Enter the value of a: "))

b = float(input("Enter the value of b: "))

try:

result = DivExp(a, b)

print("The result of the division is:", result)

except (AssertionError, ZeroDivisionError) as e:

print(e)

You might also like