Python Programming Multiple Choice Question -
Exception Handling

This section focuses on the "Exception Handling" in Python programming. These Multiple Choice Questions (mcq) should be practiced to improve the Python programming skills required for various interviews (campus interview, walk-in interview, company interview), placement, entrance exam and other competitive examinations.

1. Which block lets you test a block of code for errors?

A. try 
B. except 
C. finally 
D. None of the above

View Answer


2. What will be output for the folllowing code?

try:
  print(x)
except:
  print(""An exception occurred"")

A. x
B. An exception occurred
C. Error
D. None of the above

View Answer


3. What will be output for the folllowing code?

x = ""hello""

if not type(x) is int:
  raise TypeError(""Only integers are allowed"")

A. hello
B. garbage value
C. Only integers are allowed
D. Error

View Answer


4. What will be output for the folllowing code?

try:
  f = open(""demofile.txt"")
  f.write(""Lorum Ipsum"")
except:
  print(""Something went wrong when writing to the file"")
finally:
  f.close()

A. demofile.txt
B. Lorum Ipsum
C. Garbage value
D. Something went wrong when writing to the file

View Answer


5. Which exception raised when a calculation exceeds maximum limit for a numeric type?

A. StandardError
B. ArithmeticError
C. OverflowError
D. FloatingPointError

View Answer


6. Which exception raised in case of failure of attribute reference or assignment?

A. AttributeError
B. EOFError
C. ImportError
D. AssertionError

View Answer


7. How many except statements can a try-except block have?

A. 0
B. 1
C. more than one
D. more than zero

View Answer


8. Can one block of except statements handle multiple exception?

A. yes, like except TypeError, SyntaxError [,…]
B. yes, like except [TypeError, SyntaxError]
C. No
D. None of the above

View Answer


9. The following Python code will result in an error if the input value is entered as -5.

A. TRUE
B. FALSE
C. Can be true or false
D. Can not say

View Answer


10. What will be output for the folllowing code?

x=10
y=8
assert x>y, 'X too small

A. Assertion Error
B. 10 8
C. No output
D. 108

View Answer




Discussion



* You must be logged in to add comment.

Makkini Charan
Good