A contact list is a place where you can store a specific contact with other associated information such as a phone number, email address, birthday, etc. Write a program that first takes in word pairs that consist of a name and a phone number (both strings). That list is followed by a name, and your program should output the phone number associated with that name.
Ex: If the input is:
Joe 123-5432 Linda 983-4123 Frank 867-5309
Frank
the output is:
867-5309
Python 3 please.

Respuesta :

Answer:

# The user in prompted for input and stored in userInput

userInput = str(input("Enter the contact: "))

# The user input is splitted and stored in splitUserInput

# splitUserInput is a list because split returns a list

splitUserInput = userInput.split(" ")

# The user is prompt to enter the search contact

# The search contact will have the first letter capitalize

# should it be entered in lower case all through

searchContact = str(input("Enter the search contact: "))

# loop through the list

for i in range(len(splitUserInput)):

   # compare if the string at any value of i

   # is the same as the searchContact

   # we display the string ahead of it

   # by adding 1 to the index

   if(splitUserInput[i] == searchContact):

       print(splitUserInput[i + 1])

Explanation:

A sample screenshot is attached. The code is written in Python 3 and well commented.

The program prompt the user for input then split the input into a list. It then asked for a contact to search for. It begins looping through the list, if the search contact is found at any index, then it prints what is in front of the index.

Ver imagen ibnahmadbello
fichoh

The program returns associated phone number with a particular contact, the program is written in python 3 ;

details = str(input("Enter contact: "))

#input user details

details_split = details.split(" ")

#split the details into seperate indexes

contact = str(input("Search name: "))

for ind in range(len(details_split)):

if(details_split[ind] == contact):

#Check if the name search is the same as the detail

print(details_split[i + 1])

#display the next variable In the list which is the phone number

Learn more : https://brainly.com/question/15569615

ACCESS MORE
ACCESS MORE
ACCESS MORE
ACCESS MORE