diff --git a/lab-02/problem-06.py b/lab-02/problem-06.py index 2b2b019..e3e73cc 100644 --- a/lab-02/problem-06.py +++ b/lab-02/problem-06.py @@ -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 -# of range. \ No newline at end of file +# 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.')