Advertisements
Advertisements
प्रश्न
What is the use of a raise statement? Write a code to accept two numbers and display the quotient. Appropriate exception should be raised if the user enters the second number (denominator) as zero (0).
टीपा लिहा
Advertisements
उत्तर
The raise statement can be used to throw an exception.
The syntax of raise statement is: raise exception-name[(optional argument)]
The argument is generally a string that is displayed when the exception is raised.
code to accept two numbers and display the quotient.
n = int(input("Enter Number 1 :"))
m = int(input("Enter Number 2 :"))
if m == 0:
raise ZeroDivisionError
else:
print("Quotient : ", n / m)shaalaa.com
Raising Exceptions in Python
या प्रश्नात किंवा उत्तरात काही त्रुटी आहे का?
