Answer:
- contact_input = input("Enter contact list: ")
- contact_list = contact_input.split(" ")
- target = contact_list[len(contact_list) - 1]
- target_index = contact_list.index(target)
- print(contact_list[target_index + 1])
Step-by-step explanation:
The solution code is written in Python 3.
Firstly, use input function to get the word pairs of contacts (Line 1).
Next, use split method to break the contact_input string into a list of individual name and contact number using single space " " as separator (Line 2)
Get the index of the target contact (Line 3 - 4). The desired target contact number can be found at target_index + 1 (Line 5).