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
What helps companies and organizations to target masses of people, provide 24/7 services, and deliver better marketing in a chea
Sever21 [200]
The money their making
6 0
3 years ago
What type of software can you run to help fix computer problems?
GarryVolchara [31]

Answer:

IOBit Driver Booster.

Explanation:

3 0
3 years ago
Read 2 more answers
What obstacles could prevent you from getting and keeping a job
stepladder [879]
Drugs, No Collage, Gangs, bad grades, Criminal Records →
7 0
3 years ago
Critical thinking questions
Scrat [10]

Answer:

1: A loop will continue running until the defined condition returns false . ... You can type js for , js while or js do while to get more info on any of these. ... initialization - Run before the first execution on the loop. ... But it can be used to decrement a counter too.

2: The loop increments the value of new while the loop condition is true. The end value of new is 3.

3: We could use some sort of finger recognition or face so they don’t have to type in their password.

4: give them a second chance for their date of birth.

5: sum = 0 must be before for loop. If inside for loop, it will keep resetting sum to 0 each iteration.

Explanation:

8 0
1 year ago
You accidentally moved your task bar from the bottom of the screen to the left side. You would like to
Ratling [72]

Answer:

by pressing yes

Explanation:

ik i am a tech god

6 0
3 years ago
Read 2 more answers
Other questions:
  • What does delegating access give someone the permission to do on behalf of the user? Choose two answers.
    5·1 answer
  • Consider the attack scenario given below:
    8·1 answer
  • Reflexes are basically "hard-wired" into the CNS. Anatomically, the basis of a reflex is an afferent neuron that synapses direct
    10·1 answer
  • Mateo could not find the undo command or shortcut. He should _____.
    15·2 answers
  • Recall the insertion-sort-like algorithm in Problem 4 from Homework 2, where you know that certain pairs of contiguous items in
    15·1 answer
  • As Juan sat in his biology lab, his instructor was droning on about the techniques of vivisection. Juan kept thinking about the
    5·1 answer
  • People are still buying printed magazines?
    12·1 answer
  • Ayuda no encuentro la información de estas tres preguntas:
    10·1 answer
  • A large number of genetic codes are stored as binary values in a list. Which one of the following conditions must be true in ord
    5·2 answers
  • Convert<br> 0.625 to binary
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!