Python Lab Program 8
Python Lab Program 8
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):
if b == 0:
raise ValueError("Denominator cannot be zero")
assert a > 0, "Numerator must be positive"
return a / b
Algorithm:
1. Start
2. Define the function DivExp(a, b):
• If b (denominator) is 0:
• Raise a ValueError with the message "Denominator cannot be zero."
Output:
enter the numerator:5
enter the denominator:3
the result of the division is1.6666666666666667