computer science class 12
computer science class 12
SECTION – A
1. The errors encountered when a user violates the syntax of a programming 1
language while writing a code are termed as ______________.
a) Compile time error b) Logical Error
c) Runtime Error d) Exception
2. Write a Python program that prompts the user to input an integer and 1
raises a ValueError exception if the input is not a valid integer.
3. How can you handle exceptions in Python? 1
a) Using if-else statements
b) Using try-except blocks
c) Using switch-case statements
d) Using for loops
4. What is the purpose of the finally block in exception handling? 1
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
5. Which of the following statements is used to raise a custom exception in Python? 1
a) throw
b) raise
c) catch
d) except
6. If the file to be open in readmode, the given file must exist in the folder, 1
otherwise will raise __________
a) IOError b) EndOfError
c) TypeError d) FileNotFoundError
7. What will be the output of the following code? 1
Try:
result = 10 / 0
except ZeroDivisionError:
result = “Infinity”
print(result)
a) 10
b) “Infinity”
c) ZeroDivisionError
d) None
8. What is the purpose of the else block in exception handling? 1
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