0% found this document useful (0 votes)
10 views

computer science class 12

The document is a revision examination practice paper focused on exception handling in Python, consisting of multiple-choice questions, programming tasks, and assertion-reasoning statements. It covers topics such as types of errors, exception handling mechanisms, and the use of try-except blocks. Additionally, it includes predictive output questions and programming exercises to reinforce understanding of exception handling concepts.

Uploaded by

Kavitha Siva
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

computer science class 12

The document is a revision examination practice paper focused on exception handling in Python, consisting of multiple-choice questions, programming tasks, and assertion-reasoning statements. It covers topics such as types of errors, exception handling mechanisms, and the use of try-except blocks. Additionally, it includes predictive output questions and programming exercises to reinforce understanding of exception handling concepts.

Uploaded by

Kavitha Siva
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

REVISION EXAMINATION PRACTICE PAPER – EXCEPTION HANDLING – Marks - 40

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

Class XII Computer Science Practice Paper Page 1 of 3


9. How can you catch multiple exceptions in a single except block? 1
 Using a comma-separated list of exceptions
 Using nested try-except blocks
 By defining a custom exception
 Using the catch keyword
1 Forced exceptions are indicated using which one of the following keyword? 1
0. a) try b) raise c) except d) finally
1 What will happen if an exception is raised but not caught in a Python program? 1
1. 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
1 Justify the statement: “Every syntax error is an exception but every exception 1
2. cannot be a syntax error”.
1 What are the advantages and disadvantages of using try-except blocks 1
3. extensively in Python code?
ASSERTION AND REASONING
1 Assertion (A): Exception handling in Python allows for graceful recovery from 1
4. errors and prevents program crashes.
Reason ®: When an error occurs during program execution, Python’s
exception handling mechanism allows the program to gracefully handle the
error and take corrective action.
1 Assertion (A): Exception handling code is clear and block based in Python. 1
5. Reasoning ®: The code where unexpected runtime exception may occur is
separate from the code where the action takes place when an exception occurs.
1 Assertion: An unhandled exception in Python will terminate the program. 1
6.
Reasoning: Python does not have a mechanism to handle unhandled
exceptions, so they cause the program to halt.
1 Assertion: The finally block does not execute if an exception is raised in the try 1
7. block.

Reasoning: The finally block is designed to execute regardless of whether an


exception is raised or not, ensuring cleanup or other necessary actions.
1 Assertion: Multiple exceptions cannot be caught in a single except block; each 1
8. exception requires a separate except statement.

Reasoning: Python allows multiple exceptions to be handled in a single except


block by listing them as a tuple.
Predict the Output Questions:
1 try: 2
9. x=5/1
except ZeroDivisionError:
print(“Cannot divide by zero!”)
else:
print(“Division successful.”)
2 x = [5,8,9,13]
0.
def find_nth_value(x,n):
Class XII Computer Science Practice Paper Page 2 of 3
try:
result = x[n] 2
except IndexError as err:
print(err)
else:
print(“Your answer is “,result)
find_nth_value(x,6)
find_nth_value(x,2)
2 def divide(x,y): 2
1. try:
result = x/y
print(z)
except ZeroDivisionError :
print(“Please change ‘y’ argument to non-zero value”)
except:
print(“Something went wrong”)
else:
print(f”Your answer is {result}”)
finally:
print(“Code Finally”)
divide(1,0)
divide(1,1)
2 Write a Python program that prompts the user to input two numbers and 2
2 raises a TypeError exception if the inputs are not numerical.
2 How do you handle exceptions in Python? 2
3.
2 Write a Python program that prompts the user to input an integer and 2
4 raises a ValueError exception if the input is not a valid integer.
2 In this code: 2
5 while True:
try:
number = int(input("Please enter a number: "))
except ValueError:
print("You did not enter a valid number!")
continue
else:
print(f"The square of your number is {number**2}")
break
When does the loop end?
What should be your input in order for the try to be unsuccessful.
2 Ilustrate with example each type of exception that could occur if not 6
6 handled.(Any 6)
2 Explain the difference between syntax errors and exceptions. 2
7
-----------------
Class XII Computer Science Practice Paper Page 3 of 3

You might also like