subject

Given a variable that contains mixed collection types, update the provided function to display the first inital and last name of the instructor: Update the function to accept a list and the name of the instructor you wish to find.
Update the function to reformat the name of the instructor and return it back to the calling program.
If the instructors name is entered as John Smith then the function should return back J. Smith
If the instructors name is entered as Tracy Anne Rios then the function should return back T. Rios
If the instructors name is entered as Jackson then the function should return back Jackson
Add in any exception handling for the following scenarios:
Exceptions related to accessing the list or dictionary should output the message: Instructor not found.
All other exceptions should output the message: An error has occurred.
Test to ensure the program passes the provided test cases found in the TESTS. md file
Hints
You may only use a try/except block, no if statements
Figure out how to use only one return in the method

Tests. md:
Input

Amy Williams
Output

A. Williams
Case 2
Input

Sarah Jane Smith
Output

S. Smith
Case 3
Input

Thomas Tom
Output

Instructor not found.

What i have so far
#!/usr/bin/env python3
# Discussion 10.2: Collection Type Exceptions

# Task 1. Modify Functions for Names
def get_initial_name(initials, name):
list = instructor_name. split(' ') # this function returns a list
try:
initial = list[0][0]
name = list[-1]
f_name = initial + '. ' + name
except:
return 'Instructor not found'

# DO NOT MODIFY BELOW
if __name__ == "__main__":

courses = [
{ "name": "Amy Andrews", "courseName": "Math I", "units": 3 },
{ "name": "Bryan Bravo", "courseName": "English I", "units": 3},
{ "name": "Charles Chavez", "courseName": "Physics I", "units": 3 },
{ "name": "Daniel Diaz", "courseName": "Chemistry I", "units": 3 },
{ "name": "Edgar Allen Elam", "courseName": "Math II", "units": 3 },
{ "name": "Felicia Farr", "courseName": "Music I", "units": 3 },
{ "name": "GarthGarcia", "courseName": "Physical Education I", "units": 3 }
]

# Take Input
instructor_name = input("> ")

# Output the Result
print(get_initial_name(courses, instructor_name))

ansver
Answers: 1

Another question on Computers and Technology

question
Computers and Technology, 24.06.2019 02:30
Write the pseudo code for this problem based on what you learned from the video. the purpose is to design a modular program that asks the user to enter a distance in kilometers, and then converts that distance to miles. the conversion formula is as follows: miles = kilometers x 0.6214
Answers: 3
question
Computers and Technology, 24.06.2019 11:20
Colby works as a shipping clerk for a major package delivery service. some of his daily tasks include tracking shipments and entering orders. which aspect of the information technology cluster would he most likely be trained in? a.networkingb.databasesc.hardwared.software
Answers: 2
question
Computers and Technology, 24.06.2019 17:50
Which of the following best describe how the depth-limited search works. a normal depth-first search is performed but the number of ply/depths is limited. a normal breadth-first search is performed but the number of ply/depths is limited. a normal breadth-first search is performed but values above a specific value will be ignored. a normal depth-first search is performed but values above a specific value will be ignored.
Answers: 1
question
Computers and Technology, 25.06.2019 01:00
What phrase indicates someone has knowledge and understanding of computer,internet,mobile devices and related technologies?
Answers: 1
You know the right answer?
Given a variable that contains mixed collection types, update the provided function to display the f...
Questions
question
Mathematics, 16.11.2020 16:50
question
Computers and Technology, 16.11.2020 16:50
question
Mathematics, 16.11.2020 16:50
Questions on the website: 13722362