Given a list of 10 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. Output the message from the exception object if an IndexError is caught. Output 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:5the program outputs:Name: JaneEx: If the input of the program is:12the program outputs:Exception! list index out of rangeThe closest name is: JohnnyEx: If the input of the program is:-2the program outputs:Name: TyreseEx: If the input of the program is:-15the program outputs:Exception! list index out of rangeThe closest name is: Ryley

Respuesta :

Using the knowledge of computational language in python it is possible to write a code that given a list of 10 names, complete the program that outputs the name specified by the list index entered by the user.

Writting the code:

names = ['Ryley', 'Edan', 'Reagan', 'Henry', 'Caius', 'Jane', 'Guto', 'Sonya', 'Tyrese', 'Johnny']

index = int(input())

try:

print('Name:', names[index])

except IndexError:

print('Exception! list index out of range')

print('The closest name is :', names[0] if index < 0 else names[-1])

See more about python at brainly.com/question/18502436

#SPJ1

Ver imagen lhmarianateixeira
ACCESS MORE