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), separated by a comma. That list is followed by a name, and your program should output the phone number associated with that name. Assume the search name is always in the list.

Respuesta :

Using knowledge in computational language in python it is possible to write a code that first takes in word pairs that consist of a name and a phone number, separated by a comma.

Writting the code:

# Get the data

inputs = input("Enter the input. >>> ").split(sep=" ")

# Split the data into lists

for pos in range(len(inputs)):

   inputs[pos] = inputs[pos].split(sep=",")

# Ask for a search query

query = input("Enter a name. >>> ")

# Check for the name in the first element of each item

for item in inputs:

   if item[0] == query:

       print(f"{query}'s phone number is {item[1]}.")

       break

# Store name numbers pairs inputs in a list splitted on whitespaces

namesAndNumbersListInpWithComma = input().split(" ")

# Input the name on next line

nameOn2ndLineToLookfor = input()

# Dictionary to map the names to numbers

mappedDictOfNameandCorrsNums = {}

# Go over namesAndNumbersListInpWithComma list

for indxOfProgLoop in range(0, len(namesAndNumbersListInpWithComma)):

   # Get name and number from each item (like get 'Joe', and '123-5432' from 'Joe,123-5432')

   # Split on comma and then get the first item of list

   nameToBeMappedInDict = namesAndNumbersListInpWithComma[indxOfProgLoop].split(",")[0]

   # Split on comma and then get the second item of list

   numToBeMappedInDict = namesAndNumbersListInpWithComma[indxOfProgLoop].split(",")[1]

   # Store name and corresponding number into dictionary 'mappedDictOfNameandCorrsNums'

   mappedDictOfNameandCorrsNums[nameToBeMappedInDict] = numToBeMappedInDict

# Print the asked number with no whitespaces at the start or end by using the mapped dictionary

print((mappedDictOfNameandCorrsNums[nameOn2ndLineToLookfor]).strip())

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

#SPJ1

Ver imagen lhmarianateixeira