0
0
Pythonprogramming~20 mins

Common exception types in Python - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Exception Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the output of this code?
Look at the code below. What will it print when run?
Python
try:
    x = 5 / 0
except ZeroDivisionError:
    print("Error caught")
AZeroDivisionError
BError caught
C5
DNo output
Attempts:
2 left
💡 Hint
Think about what happens when you divide by zero in Python.
Predict Output
intermediate
2:00remaining
What error does this code raise?
What error will this code produce when run?
Python
my_list = [1, 2, 3]
print(my_list[5])
AIndexError
BKeyError
CTypeError
DValueError
Attempts:
2 left
💡 Hint
Think about what happens when you try to access a list element with an invalid index.
Predict Output
advanced
2:00remaining
What is the output of this code?
What will this code print?
Python
d = {'a': 1, 'b': 2}
try:
    print(d['c'])
except KeyError:
    print('Key not found')
AKeyError
B1
CKey not found
DNone
Attempts:
2 left
💡 Hint
What happens when you try to access a dictionary key that does not exist?
Predict Output
advanced
2:00remaining
What error does this code raise?
What error will this code produce?
Python
x = 'hello'
print(x + 5)
ATypeError
BValueError
CNameError
DSyntaxError
Attempts:
2 left
💡 Hint
Think about adding a string and a number.
Predict Output
expert
2:00remaining
What is the output of this code?
What will this code print when run?
Python
try:
    a = int('abc')
except ValueError:
    print('Conversion failed')
else:
    print('Conversion succeeded')
ANo output
BConversion succeeded
CValueError
DConversion failed
Attempts:
2 left
💡 Hint
What happens when you try to convert a non-numeric string to int?