Advertisements
Advertisements
Question
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.
Short/Brief Note
Advertisements
Solution
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 itshaalaa.com
Handling Exceptions in Python
Is there an error in this question or solution?
