1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Natali [406]
3 years ago
13

1 #Write a function called phonebook that takes two lists as

Computers and Technology
1 answer:
Nesterboy [21]3 years ago
7 0

Answer:

I am writing a Python program.

def phonebook(names, numbers):  #method phonebook that takes two parameters i.e a list of names and a list of phone numbers

   dict={}  #creates a dictionary

   for x in range(len(names)):  # loop through the names

       dict[names[x]]=numbers[x]  #maps each name to its phone number

   return dict #return dictionary in key:value form i.e. name:number

#in order to check the working of this function, provide the names and numbers list and call the function as following:

names = ['Jackie', 'Joshua', 'Marguerite']

numbers = ['404-555-1234', '678-555-5678', '770-555-9012']

print(phonebook(names, numbers))

Explanation:

The program has a function phonebook() that takes two parameters, name which is a list of names and numbers that is a list of phone numbers.

It then creates a dictionary. An empty dictionary is created using curly brackets. A dictionary A dictionary is used here to maps a names (keys) phone numbers (values) in order to create an unordered list of names and corresponding numbers.

for x in range(len(names)):  

The above statement has a for loop and two methods i.e. range() and len()

len method is used to return the length of the names and range method returns sequence of numbers just to iterate as an index and this loops keeps iterating until x exceeds the length of names.

dict[names[x]]=numbers[x]

The above statement maps each name to its phone number by mapping the first name with the first  umber, the second name with the second number and so on. This mapping is done using x which acts like an index here to map first name to first number and so on. For example dict[names[1]]=numbers[1]  will map the name (element) at 1st index of the list to the number (element) at 1st index.

return dict retursn the dictionary and the format of dictionary is key:value where key is the name and value is the corresponding number.

The screenshot of the program and its output is attached.

You might be interested in
You browsing internet and you realize that its not responding what do you do with out rebooting the computer
Allisa [31]
You can try and turn wifi off then on press save on whatever you were doing if you can then reboot it. other then that theres not many more options.
4 0
3 years ago
Innovation made from establishment of abucas to the present 5th
Minchanka [31]

Answer:

Douglas-fir, spruce, true fir, beech, and maple are toward the top of the list for oxygen release.Douglas-fir, spruce, true ...

4 0
3 years ago
JAVA
Vlada [557]

Answer:

Answer is in the attached screenshot!

Explanation:

Iterate through the given input strings, create a student class with the given name, assign the output array to the value of the class created from the given input string. Finally, return the array.

8 0
3 years ago
Hope has now created her sublist. 1. Oxygen a. Helps living things produce energy b. Helps protect living things from harmful ra
Alex_Xolod [135]

Answer: 1. put her insertion point at the end of item 2b. 2. press enter key

5 0
3 years ago
A pangram is a sentence that contains all the letters of the English alphabet at least once. For example, the quick brown fox ju
erma4kov [3.2K]
Do you want this in paragraph form ?
5 0
3 years ago
Other questions:
  • To move to the most extreme right cell containing data in your worksheet, what basic key combination can you use?
    7·1 answer
  • What are the People that make the goods called
    14·1 answer
  • In order to plan George’s birthday, his father gave him a list of people who attended his birthday for the last five years. What
    8·2 answers
  • . What is automated testing?
    10·1 answer
  • Draw a logic circuit for the function F = (A + B)(B + C)(A + C), using NOR gates only. ​
    9·1 answer
  • 1. Consider a direct-mapped cache that can accommodate 8Mbytes from a main memory, that uses a 32-bit address and 32-byte blocks
    5·1 answer
  • 60 POINTS IF YOU GET IT RIGHT
    6·2 answers
  • What is the ls option to list entries by lines instead of by columns?​
    11·1 answer
  • How to implement switch statement in Python?
    11·2 answers
  • Which type of computer is used microprocessor​
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!