CUET Computer Science MCQs Chapter 1 Exception and File Handling in Python

Refer to CUET Computer Science MCQs Chapter 1 Exception and File Handling in Python provided below available for download in Pdf. The MCQ Questions for UG Computer Science with answers are aligned as per the latest syllabus and exam pattern suggested by CUET, NCERT and KVS. Multiple Choice Questions for Chapter 1 Exception and File Handling in Python are an important part of exams for UG Computer Science and if practiced properly can help you to improve your understanding and get higher marks. Refer to more Chapter-wise MCQs for CUET UG Computer Science and also download more latest study material for all subjects

MCQ for UG Computer Science Chapter 1 Exception and File Handling in Python

UG Computer Science students should refer to the following multiple-choice questions with answers for Chapter 1 Exception and File Handling in Python in UG.

Chapter 1 Exception and File Handling in Python MCQ Questions UG Computer Science with Answers

Question. What is an exception in Python?
a) A syntax error
b) A runtime error
c) A logical error
d) A compile-time error

Answer : B

Question. Which of the following file methods directly returns a list where each element is a line from the file?
a) read()
b) readline()
c) readlines()
d) readchar()

Answer : C

Question. What will be the output of the following code?
try:
result = 10 / 0
except ZeroDivisionError:
result = "Infinity"
print(result)
a) 10
b) "Infinity"
c) ZeroDivisionError
d) None

Answer : B

Question. When does the search for an appropriate exception handler occur in the process of exception handling?
a) Before the exception object is created.
b) After an exception is raised but before it is executed.
c) After the exception is executed.
d) Parallelly as the exception object is created.

Answer : B

Question. What does the finally block execute if an exception is raised and not caught?
a) It doesn't execute
b) It executes before the exception is raised
c) It executes after the exception is raised
d) It executes only if the exception is caught

Answer : C

Question. Which of the following steps is NOT part of the exception handling process?
a) Automatically correcting all programming errors without any additional code.
b) Raising an exception when an error occurs.
c) Searching for an exception handler after an exception is raised.
d) Executing the exception handler's code to manage the error.

Answer : A

Question. What is the purpose of the raise statement in Python?
a) To raise an arbitrary exception
b) To terminate the program
c) To catch an exception
d) To ignore an exception

Answer : A

Question. Consider the following python code: def myDiv(x, y): if
y = = 0:
raise ZeroDivisionError
return x/y
What is the output of the following?
n = myDiv(4,0)
print(n)

a) 0.0
b) No output
c) ZeroDivisionError
d) ValueError

Answer : C

Question. What does the "?" pattern represent in RegEx?
a) Zero or more occurrences
b) One or more occurrences
c) Zero or one occurrence
d) Exactly one occurrence

Answer : A

Question. Read the following statements and arrange in correct order.
A. Exception is raised
B. Executes exception
C. Program searches for exception handler
D. Create exception object
E. An error encountered
Choose the correct answer from the options given below:

a) A→B→C→D→E
b) E→D→C→A→B
c) E→D→B→C→A
d) E→D→A→C→B

Answer : D

Question. What does the "(?P<name>...)" construct do in a RegEx pattern?
a) Denotes a positive lookahead
b) Captures a named group
c) Represents a character class
d) Defines a negative lookahead

Answer : B

Question. Which statement is/are true about Exception handling?
i. There can be try block without catch block but vice versa is not possible.
ii. There is no limit on the number of catch, block corresponding to a try block.
iii. The object must be created of a specific class of which the error has occurred otherwise runtime error will occur.
iv. To execute a code with each and every run of program, the code is written in finally block.

a) i and ii, iv
b) Only iii
c) ii and iv Only
d) Only ii

Answer : A

Question. How can you match a word that ends with "py" in RegEx?
a) py$
b) \bpy
c) py\b
d) ^py

Answer : C

Question. In Python code, on encountering a syntax error, the _____________ does not execute the program.
a) Processor
b) Editor
c) Interpreter
d) Converter

Answer : C

Question. How can you handle exceptions in Python?
a) Using if-else statements
b) Using try-except blocks
c) Using switch-case statements
d) Using for loops

Answer : B

Question. What will be the output of the following Python code:
a=5.2
try:
  print(a)
except NameError:
  print("Variable a is not defined")
except ValueError:
  print("The value of a must be an integer")

a) The value of a must be an integer
b) Variable a is not defined
c) 5.2
d) 5

Answer : C

Question. How can you catch multiple exceptions in a single except block?
a) Using a comma-separated list of exceptions
b) Using nested try-except blocks
c) By defining a custom exception
d) Using the catch keyword

Answer : A

Question. Which of the following error will be raised by the given Python code:
randomList = ['a', 2, 3]
for element in randomList:
        print("The element is ", element)
        x = int(element+1)
print("The incremeant of ", element, "is", x)

a) NameError
b) ValueError
c) TypeError
d) IOError

Answer : C

Question. What will happen if an exception is raised but not caught in a Python program?
a) The program will terminate abruptly
b) The program will continue to execute without any impact
c) The program will print an error message and continue
d) The program will prompt the user to handle the exception

Answer : A

Question. What will be the output of the following Python code:
a = [4, 5, 6, 7]
try:
    print ("First element is %d" %(a[2]))
    print ("Fifth element is %d" %(a[5])) 
except:
    print ("Error")

a) Error
b) First element is 6 Error
c) First element is 6
Fifth element is 7
d) First element is 4 Error

Answer : B

Question. Which method is used to replace a pattern in a string using RegEx?
a) replace()
b) substitute()
c) re.replace()
d) sub()

Answer : D

Question. How can you make a RegEx pattern match across multiple lines in Python?
a) re.MULTILINE
b) re.SINGLELINE
c) re.LINEALL
d) re.GLOBAL

Answer : A

Question. Which type of error will be raised by the following Python code:
x = 10
y = 20
if (y > x)
  print("y is greater than x")

a) ValueError
b) TypeError
c) IOError
d) Syntax Error

Answer : D

Question. What is the purpose of the finally block in exception handling?
a) To define a block of code that will be executed if an exception occurs
b) To specify the code to be executed regardless of whether an exception occurs or not
c) To catch and handle specific exceptions
d) To raise a custom exception

Answer : B

Question. Which of the following is not a built-in exceptions in Python?
a) ZeroDivisionError
b) OverFlowError
c) KeyboardInterrupt
d) None of the above

Answer : D

Question. What is the purpose of the assert statement in Python exception handling?
a) To catch and handle exceptions
b) To raise a custom exception
c) To check if a given expression is true, otherwise raise an 'AssertionError'
d) To ignore exceptions

Answer : C

Question. What will be the output of the following Python code:
a = 1
if (a = 2):
  print("value of a is", a)

a) value of a is 2
b) value of a is 1
c) IOError
d) Syntax Error

Answer : D

Question. How can you re-raise an exception in Python?
a) Using the retry statement
b) Using the throw statement
c) Using the raise statement without any arguments
d) Using the rethrow keyword

Answer : C

Question. Consider the following Python code and identify the line number(s) which has some error. Assume that the user wants to print the reverse of the given list:
languages = ['java','python','C++']   #List
for i in range(len(languages),0,-1):  #Line-1
print(Languages[i],end=' ')               #Line-2

a) Line-1
b) Line-2
c) Both Line-1 and Line-2
d) No Error.

Answer : C

Question. Which method is used to check if a pattern is present anywhere in a string using RegEx?
a) search()
b) match()
c) find()
d) locate()

Answer : A

Question. Which of the following statements is used to raise a custom exception in Python?
a) throw
b) raise
c) catch
d) except

Answer : B

Question. What is the output produced by the following lines of code if 1 is passed as input 
a=input()
print("Testing code")
try:
    if a=1:
        print(True)
except:
    print(False)

a) Testing code
True
b) Testing code
False
c) Testing code
SyntaxError
d) SyntaxError

Answer : D

Question. How can you handle exceptions globally in Python?
a) Using the `global_exception_handler()` function
b) By modifying the global exception settings in the `sys` module
c) By using the `global` keyword
d) There is no way to handle exceptions globally

Answer : B

Question. Which character is used to match any whitespace character in RegEx?
a) \s
b) \S
c) \w
d) \W

Answer : A

Question. What does the "re.IGNORECASE" flag do in Python RegEx?
a) Enables case-sensitive mode
b) Disables case-sensitive mode
c) Matches Unicode characters
d) Ignores case

Answer : D

Question. What is the purpose of the else block in exception handling?
a) To handle exceptions
b) To specify code that will be executed if no exceptions are raised
c) To define custom exceptions
d) To skip the execution of the block if an exception occurs

Answer : B

Question. How can you match a word that ends with "ly" in RegEx?
a) \bly$
b) ly\b
c) ^ly
d) \bly\b

Answer : B

Question. What is the purpose of the with statement in Python exception handling?
a) To create a new exception
b) To simplify resource management using context managers
c) To catch and handle exceptions
d) To define a custom exception

Answer : B

Question. In Python, what does the sys.exc_info() function return?
a) The exception type
b) The exception value
c) A tuple containing the exception type, value, and traceback
d) A dictionary containing exception information

Answer : C

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

MCQs for Chapter 1 Exception and File Handling in Python Computer Science UG

Expert teachers of studiestoday have referred to NCERT book for UG Computer Science to develop the Computer Science UG MCQs. If you download MCQs with answers for the above chapter you will get higher and better marks in UG test and exams in the current year as you will be able to have stronger understanding of all concepts. Daily Multiple Choice Questions practice of Computer Science will help students to have stronger understanding of all concepts and also make them expert on all critical topics. After solving the questions given in the MCQs which have been developed as per latest books also refer to the NCERT solutions for UG Computer Science. We have also provided lot of MCQ questions for UG Computer Science so that you can solve questions relating to all topics given in each chapter. After solving these you should also refer to UG Computer Science MCQ Test for the same chapter.

Where can I download latest CUET MCQs for UG Computer Science Chapter 1 Exception and File Handling in Python

You can download the CUET MCQs for UG Computer Science Chapter 1 Exception and File Handling in Python for latest session from StudiesToday.com

Are the UG Computer Science Chapter 1 Exception and File Handling in Python MCQs available for the latest session

Yes, the MCQs issued by CUET for UG Computer Science Chapter 1 Exception and File Handling in Python have been made available here for latest academic session

Where can I find CUET UG Computer Science Chapter 1 Exception and File Handling in Python MCQs online?

You can find CUET UG Computer Science Chapter 1 Exception and File Handling in Python MCQs on educational websites like studiestoday.com, online tutoring platforms, and in sample question papers provided on this website.

How can I prepare for Chapter 1 Exception and File Handling in Python UG MCQs?

To prepare for Chapter 1 Exception and File Handling in Python MCQs, refer to the concepts links provided by our teachers and download sample papers for free.

Are there any online resources for CUET UG Computer Science Chapter 1 Exception and File Handling in Python?

Yes, there are many online resources that we have provided on studiestoday.com available such as practice worksheets, question papers, and online tests for learning MCQs for UG Computer Science Chapter 1 Exception and File Handling in Python