Recall & Review
beginner
What is a ValueError in Python?
A ValueError happens when a function receives an argument of the right type but an inappropriate value. For example, trying to convert a letter to an integer.
Click to reveal answer
beginner
Explain TypeError with an example.
A TypeError occurs when an operation or function is applied to an object of an inappropriate type. For example, adding a number and a string together.
Click to reveal answer
beginner
What does IndexError mean?
IndexError happens when you try to access an index that is outside the range of a list or other sequence.
Click to reveal answer
beginner
Describe KeyError in Python dictionaries.
KeyError occurs when you try to access a dictionary key that does not exist.
Click to reveal answer
beginner
What is a ZeroDivisionError?
A ZeroDivisionError happens when you try to divide a number by zero, which is not allowed in math.
Click to reveal answer
Which exception is raised when you try to access a list element with an invalid index?
✗ Incorrect
Accessing an invalid index in a list raises an IndexError.
What exception occurs when you try to add a number and a string?
✗ Incorrect
Adding incompatible types like number and string causes a TypeError.
If you try to get a dictionary value using a key that does not exist, which exception is raised?
✗ Incorrect
Accessing a missing key in a dictionary raises a KeyError.
Which exception is raised when you try to convert the string 'abc' to an integer?
✗ Incorrect
Trying to convert a non-numeric string to int raises a ValueError.
What exception occurs when dividing a number by zero?
✗ Incorrect
Dividing by zero raises a ZeroDivisionError.
List and explain three common Python exceptions you might encounter when working with lists and dictionaries.
Think about accessing elements and types.
You got /4 concepts.
Describe what causes a ValueError and a ZeroDivisionError in Python with simple examples.
Consider wrong values and division by zero.
You got /3 concepts.