Question: 1 0 . 9 . 1 : LAB: Exceptions with lists Given a list of 1 0 names, complete the program that outputs the name
: LAB: Exceptions with lists
Given a list of names, complete the program that outputs the name specified by the list index entered by the user. Use a try block to output the name and an except block to catch any IndexError exception as a variable. Output 'Exception! followed by the message from the exception variable. Output also the first element in the list if the invalid index is negative or the last element if the invalid index is positive.
Note: Python allows using a negative index to access a list, as long as the magnitude of the index is smaller than the size of the list. Ex If the input of the program is:
the program outputs:
Name: Jane
Ex: If the input of the program is:
the program outputs:
Exception! list index out of range
The closest name is: Johnny
Ex: If the input of the program is:
the program outputs:
Name: Tyrese
Ex: If the input of the program is:
the program outputs:
Exception! list index out of range
The closest name is: Ryley
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
