0% found this document useful (0 votes)
3 views6 pages

Exception Handling Class 12 MCQ

The document contains multiple-choice questions (MCQs) related to Exception Handling and File Handling in Python for Class 12. It covers various types of errors, exception handling mechanisms, and file operations, including reading and writing modes. Each question is followed by the correct answer, providing a comprehensive overview of the topics.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views6 pages

Exception Handling Class 12 MCQ

The document contains multiple-choice questions (MCQs) related to Exception Handling and File Handling in Python for Class 12. It covers various types of errors, exception handling mechanisms, and file operations, including reading and writing modes. Each question is followed by the correct answer, providing a comprehensive overview of the topics.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Exception Handling Class 12 MCQ

1. __ errors can occur when the programmer does not follow the rules of
the particular programming language.
a. Syntax error
b. Runtime error
c. Logical error

Answer ⟵a. Syntax error


d. None of the above

2. Which error is known as a parsing error?


a. Syntax error
b. Runtime error
c. Logical error

Answer ⟵a. Syntax error


d. None of the above

3. Errors can be handled using a __.


a. Function
b. Variable
c. Exception

Answer ⟵c. Exception


d. None of the above

4. __ raised when there is an error in the syntax of the Python code.


a. SyntaxError
b. IOError
c. ZeroDivisionError

Answer ⟵a. SyntaxError


d. TypeError

5. __ error raised when the denominator in a division operation is zero.


a. SyntaxError
b. IOError
c. ZeroDivisionError

Answer ⟵c. ZeroDivisionError


d. TypeError

6. __ error raised when the file specified in a program statement cannot


be opened.
a. SyntaxError
b. IOError
c. ZeroDivisionError

Answer ⟵b. IOError


d. TypeError

7. A programmer can create custom exceptions to suit one’s


requirements; it is known as _.
a. Predefined exceptions
b. User-defined exceptions
c. Custom exceptions
d. None of the above
Answer ⟵b. User-defined exceptions
8. What is the purpose of the ‘raise’ statement in Python?
a. To handle exceptions
b. For log error
c. To explicitly trigger an exception

Answer ⟵c. To explicitly trigger an exception


d. None of the above

9. Which of the following is a correct syntax of the ‘raise’ statement?


a. raise(‘Error message’)
b. raise Exception(‘Error message’)
c. Both a) and b)

Answer ⟵b. raise Exception(‘Error message’)


d. None of the above

10. Which statement in Python is used to test an expression in the


program code?
a. raise statement
b. assert statement
c. Both a) and b)

Answer ⟵b. assert statement


d. None of the above

11. Writing additional code in a program to give proper messages or


instructions to the user on encountering an exception. This process is
known as _.
a. Error handling
b. Exception handling
c. Raise handling

Answer ⟵b. Exception handling


d. Assert handling

12. In exception handling, when an error occurs, the Python interpreter


creates an object called __.
a. Error object
b. Exception object
c. Assert object

Answer ⟵Exception object


d. Raise object

13. Exception object contain which type of information.


a. Error type
b. file name
c. Error position in the program

Answer ⟵d. All of the above


d. All of the above

14. This process of creating an exception object and handing it over to


the runtime system is called _.
a. Error an exception
b. Throwing an exception
c. Handling an exception

Answer ⟵b. Throwing an exception


d. None of the above

15. Every try block is followed by an __ block.


a. Type
b. Size
c. Except

Answer ⟵c. Except


d. None of the above

File Handling in Python MCQ


1. A text file stores information is __________ characters.
a. ASCII
b. Unicode
c. Both a) and b)

Answer ⟵c. Both a) and b)


d. None of the above

2. In text files, each line of text is terminated, with a special character


known as ___________.
a. EOL
b. EOF
c. EEF

Answer ⟵a. EOL


d. All of the above

3. Which one of the following is correct for carriage-return and newline


combination.
a. \r\n
b. /r/n
c. \r/n

Answer ⟵a. \r\n


d. /r\n

4. A _________ file is just a file that contains information in the same


format in which the information is held in memory.
a. Text file
b. Binary file
c. Word file

Answer ⟵b. Binary file


d. None of the above

5. _________file format are faster and easier for a prgram to read and
write than other file format.
a. Text file
b. Binary file

d. None of the above Answer ⟵b. Binary file


c. Doc file

6. The command for opening a file in Python file handling is


____________.
a. open()
b. update()
c. both a) and b)

Answer ⟵a. open()


d. None of the above

7. The command for closing a file in Python file handling is


____________.
a. close()
b. closing()
c. object()

Answer ⟵a. close()


d. None of the above

8. _________ text file mode is used to read data from file.


a. ‘r’
b. ‘rb’
c. ‘r+’

Answer ⟵a. ‘r’


d. None of the above

9. _________ text file mode is used to apped data in the file using file
handling.
a. ‘w’
b. ‘ab’
c. ‘a’

Answer ⟵c. ‘a’


d. None of the above

10. _________ binary file mode is used to append data in the file using
file handling.
a. ‘ab’
b. ‘w’
c. ‘a’

Answer ⟵a. ‘ab’


d. None of the above

11. Which of the following option is correct for ‘a+’ text file mode.
a. File is create if does not exit
b. If file exist, file’s existing data is retained; new data is appended
c. Both reading and writing operation can take palce.

Answer ⟵d. All of the above


d. All of the above

12. ___________ function is used to read the data from the file.
a. read()
b. readline()
c. readlines()

Answer ⟵d. All of the above


d. All of the above

13. Which function is used to write data onto a file.


a. write()
b. writelines()
c. Both a) and b)

Answer ⟵c. Both a) and b)


d. None of the above

14. Python holds everything to write in the file in buffer. if you want to
force python to write the contents of buffer onto storage, you can use
________ function.
a. flush()
b. push()
c. clear()

Answer ⟵a. flush()


d. None of the above

15. Which function is used to remove whitespace after reading a file in


file handling.
a. write()
b. read()
c. strip()

Answer ⟵c. strip()


d. None of the above

16. _________ removes the given character from trailing end or from the
right end.
a. strip()
b. rstrip()
c. lstrip()

Answer ⟵b. rstrip()


d. None of the above

17. A text file can be opened in ________ file modes.


a. ‘r’ and ‘w’
b. ‘a’ and ‘r+’
c. ‘w+’ and ‘a+’

Answer ⟵d. All of the above


d. All of the above

18. A binary file can be opend in ________ file mode.


a. ‘rb’ and ‘wb’
b. ‘ab’ and ‘r+b’
c. (‘rb+’), ‘w+b'(wb+’), ‘a+b'(‘ab+’)

Answer ⟵d. All of the above


d. All of the above

19. ________ are the standard streams in file handling.


a. stdin (standard input)
b. stdout (standard output)
c. stderr (standard error)

Answer ⟵d. All of the above


d. All of the above

20. The input and output devices are implemented as file, also called
__________.
a. Standard streams
b. Standard Binary
c. Standar Text

Answer ⟵a. Standard streams


d. None of the above

21. In python directory denonted as a dot(.) while its parent directory is


denoted with ________.
a. Three dots(…)
b. Two dots(..)
c. Both a) and b)

Answer ⟵b. Two dots(..)


d. None of the above

You might also like