Computer Science
List the situation(s) in which the following errors occur:
(a) IOError
(b) NameError
(c) ValueError
(d) TypeError
Python Exception Handling
3 Likes
Answer
(a) IOError — This error is raised if the requested file cannot be opened, or failure of I/O operation.
(b) NameError — This error is raised when an identifier is not found in the local or global namespace.
(c) ValueError — This error is raised when a built-in operation or function receives an argument that has the right type but an inappropriate value.
(d) TypeError — This error is raised when an operation or function is attempted that is invalid for the specified data type.
Answered By
1 Like
Related Questions
Assertion (A): No matter what exception occurs, you can always make sure that some common action takes place for all types of exceptions.
Reasoning (R): The finally block contains the code that must execute.
- Both A and R are true and R is the correct explanation of A.
- Both A and R are true but R is not the correct explanation of A.
- A is true but R is false.
- A is false but R is true.
What all can be the possible outputs of the following code?
def myfunc (x=None) : result = "" if x is None: result = "No argument given" elif x == 0: result = "Zero" elif 0 < x <= 3: result = "x is between 0 and 3" else: result = "x is more than 3" return result c = myfunc (3.5) print (c)
Name three run-time errors that occur during Python program execution.
What is the difference between an error and exception?