
Python Exception Quiz
Authored by Ali Fakhri
Computers
Vocational training
Used 1+ times

AI Actions
Add similar questions
Adjust reading levels
Convert to real-world scenario
Translate activity
More...
Content View
Student View
12 questions
Show all answers
1.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
What is an exception in Python?
c) A data type in Python
d) A method to handle missing values
b) A signal that an error has occurred
a) A function that returns an error
Answer explanation
An exception in Python is b) a signal that an error has occurred. It indicates that something unexpected happened during program execution, allowing developers to handle errors gracefully.
2.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
Which of the following keywords is used to handle exceptions in Python?
c) exception
a) try
b) error
d) raise
Answer explanation
In Python, the 'try' keyword is used to handle exceptions. It allows you to write code that can catch and respond to errors gracefully, making it the correct choice for exception handling.
3.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
Which block is executed regardless of whether an exception occurs or not?
a) else
b) except
c) finally
d) raise
Answer explanation
The 'finally' block is executed after the try and except blocks, regardless of whether an exception was raised or not. This ensures that cleanup code runs in all scenarios, making 'finally' the correct choice.
4.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
What will happen if an exception is not handled in Python?
c) The program will fix the error
a) The program will run normally
d) Python will continue running the next line
b) The program will crash
Answer explanation
If an exception is not handled in Python, the program will crash, terminating execution and displaying an error message. Thus, the correct answer is b) The program will crash.
5.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
Which of the following is used to manually throw an exception in Python?
a) throw
b) trigger
c) raise
d) throwError
Answer explanation
In Python, the 'raise' statement is used to manually throw an exception. The other options, 'throw', 'trigger', and 'throwError', are not valid keywords for this purpose.
6.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
What exception will this code raise? `x = int("abc")`
d) IndexError
c) KeyError
b) TypeError
a) ValueError
Answer explanation
The code `x = int("abc")` attempts to convert a non-numeric string to an integer, which is invalid. This raises a ValueError, indicating that the string cannot be interpreted as an integer. Thus, the correct answer is a) ValueError.
7.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
What will happen when the following code is executed? `my_list = [1, 2, 3] print(my_list[5])`
b) KeyError
a) IndexError
d) ValueError
c) TypeError
Answer explanation
The code attempts to access the 6th element (index 5) of a list that only has 3 elements (indices 0, 1, 2). This results in an IndexError, indicating that the index is out of range. Therefore, the correct answer is a) IndexError.
Access all questions and much more by creating a free account
Create resources
Host any resource
Get auto-graded reports

Continue with Google

Continue with Email

Continue with Classlink

Continue with Clever
or continue with

Microsoft
%20(1).png)
Apple
Others
Already have an account?