Advertisements
Advertisements
प्रश्न
You have learnt how to use math module in Class XI. Write a code where you use the wrong number of arguments for a method (say sqrt() or pow()). Use the exception handling process to catch the ValueError exception.
Advertisements
उत्तर
Code to show the wrong number of arguments with exception handling.
import math
try:
print(math.sqrt(25,6))
except TypeError:
print("Wrong number of arguments used in sqrt() ")
finally:
print("Okay, Correct it")
Output:
Wrong number of arguments used in sqrt()
Okay, Correct itAPPEARS IN
संबंधित प्रश्न
How many except statements can a try-except block have?
When will the else part of try-except-else be executed?
Can one block of except statements handle multiple exceptions?
Which of the following blocks lets you test a block of code for errors?
What is not true for exception handling?
While executing the program, if an exception is encountered in try block then execution of the code inside the try block is stopped and:
The else part of try-except-else executes:
Define the following:
Exception Handling
Define the following:
Throwing an exception
Define the following:
Catching an exception
Explain catching exceptions using try and except block.
Predict the output of the Python code given below:
def Diff(N1,N2):
if N1>N2:
return N1-N2
else:
return N2-N1
NUM= [10,23,14,54,32]
for CNT in range (4,0,-1):
A=NUM[CNT]
B=NUM[CNT-1]
print(Diff(A,B),'#', end=' ')“In a Python program, if a break statement is given in a nested loop, it terminates the execution of all loops in one go.”
