feat: completed problem-06.py
This commit is contained in:
@@ -1,2 +1,12 @@
|
|||||||
# Write a Python program that executes an operation on a list and handles an IndexError exception if the index is out
|
# Write a Python program that executes an operation on a list and handles an IndexError exception if the index is out
|
||||||
# of range.
|
# of range.
|
||||||
|
|
||||||
|
# Defines 'test_list' var with 4 elements, indices 0-3.
|
||||||
|
test_list = ['a', 'b', 'c', 'd']
|
||||||
|
# Try printing the 4th index in the list
|
||||||
|
try:
|
||||||
|
print(test_list[4])
|
||||||
|
# Handle the expected IndexError
|
||||||
|
except IndexError:
|
||||||
|
# Print an error message
|
||||||
|
print('That list entry does not exist.')
|
||||||
|
|||||||
Reference in New Issue
Block a user