English

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 - Computer Science (Python)

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 Note

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 it
shaalaa.com
Handling Exceptions
  Is there an error in this question or solution?
Chapter 1: Exception Handling in Python - Exercise [Page 18]

APPEARS IN

NCERT Computer Science [English] Class 12
Chapter 1 Exception Handling in Python
Exercise | Q 8. | Page 18
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×