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

Program 8

The document describes a Python function named DivExp that performs division of two numbers, a and b, with error handling for division by zero. It includes assertions to ensure a is greater than zero and raises an exception when b is zero. The program prompts the user for input values and displays the result of the division or an error message if applicable.

Uploaded by

Bhagyashree
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)
2 views1 page

Program 8

The document describes a Python function named DivExp that performs division of two numbers, a and b, with error handling for division by zero. It includes assertions to ensure a is greater than zero and raises an exception when b is zero. The program prompts the user for input values and displays the result of the division or an error message if applicable.

Uploaded by

Bhagyashree
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

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.

Program:
def DivExp(a,b):

try:

c=a/b

except ZeroDivisionError:

print('Error: Division by zero')

else:

return c

a = int(input('Enter the Divident value of \'a\': '))

b = int(input('Enter the Divisor value of \'b\': '))

d = DivExp(a,b)

if d is not None:

print('The result of division is: ', d)

else:

print('The result of division is: infinity')

OUTPUT
Enter the Divident value of 'a': 6
Enter the Divisor value of 'b': 0
Error: Division by zero
The result of division is: infinity

Enter the Divident value of 'a': 8


Enter the Divisor value of 'b': 2
The result of division is: 4.0
[ ]:

You might also like