Question

Create a new program in Mu and save it as ps4.5.1.py and take the code below...

Create a new program in Mu and save it as ps4.5.1.py and take the code below and fix it as indicated in the comments:

# Write a function called phonebook that takes two lists as
# input:
#
# - names, a list of names as strings
# - numbers, a list of phone numbers as strings
#
# phonebook() should take these two lists and create a
# dictionary that maps each name to its phone number. For
# example, the first name in names should become a key in
# the dictionary, and the first number in numbers should
# become the value corresponding to the first name. Then, it
# should return the dictionary that results.
#
# Hint: Because you're mapping the first name with the first
# number, the second name with the second number, etc., you do
# not need two loops. For a similar exercise, check back on
# Coding Problem 4.3.3, the Scantron grading problem.
#
# You may assume that the two lists have the same number of
# items: there will be no names without numbers or numbers
# without names.

# Write your function here!

# Below are some lines of code that will test your function.
# You can change the value of the variable(s) to test your
# function with different inputs.
#
# If your function works correctly, this will originally
# print (although the order of the keys may vary):
# {'Jackie': '404-555-1234', 'Joshua': '678-555-5678', 'Marguerite': '770-555-9012'

name_list = ['Jackie', 'Joshua', 'Marguerite']
number_list = ['404-555-1234', '678-555-5678', '770-555-9012']
print(phonebook(name_list, number_list))
0 0
Add a comment Improve this question Transcribed image text
Answer #1

def phonebook(name_list, number_list): return dict(zip(name_list, number_list))#use zip if we are not using loops|| name_list

def phonebook(name_list,number_list):
return dict(zip(name_list,number_list))#use zip if we are not using loops
  


name_list = ['Jackie', 'Joshua', 'Marguerite']
number_list = ['404-555-1234', '678-555-5678', '770-555-9012']
print(phonebook(name_list,number_list))

Input {Marguerite: 770-555-9012, Joshua: 678-555-5678, Jackie: 404-555-1234}

Comment if any doubts

Add a comment
Know the answer?
Add Answer to:
Create a new program in Mu and save it as ps4.5.1.py and take the code below...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Create a new program in Mu and save it as ps4.5.3.py and take the code below...

    Create a new program in Mu and save it as ps4.5.3.py and take the code below and fix it as indicated in the comments: # In the Pokemon video game series, every Pokemon has six # stats: HP, Attack, Defense, Special Attack, Special Defense, # and Speed. # # Write a function called total_stats that will take as input # a list of dictionaries. Each dictionary will have seven # key-value pairs: # # - name: a Pokemon's name #...

  • Create a new program in Mu and save it as ps4.5.2.py and take the code below...

    Create a new program in Mu and save it as ps4.5.2.py and take the code below and fix it as indicated in the comments: # Do not change the line of code below. It's at the top of # the file to ensure that it runs before any of your code. # You will be able to access french_dict from inside your # function. french_dict = {"me": "moi", "hello": "bonjour", "goodbye": "au revoir", "cat": "chat", "dog": "chien", "and": "et"} #...

  • Create a new program in Mu and save it as ps4.3.1.py and take the code below...

    Create a new program in Mu and save it as ps4.3.1.py and take the code below and fix it as indicated in the comments: # Write a function called grade_scantron. grade_scantron should # take as input two lists: answers and key. Each list contain # strings. Each string will be only one letter, a character # from A to E. grade_scantron should return how many questions # the student got "right", where a student gets a question # right if...

  • Create a new program in Mu and save it as ps3.4.1.py and take the code below...

    Create a new program in Mu and save it as ps3.4.1.py and take the code below and fix it as indicated in the comments: # Write a function called hide_and_seek. The function should # have no parameters and return no value; instead, when # called, it should just print the numbers from 1 through 10, # follow by the text "Ready or not, here I come!". Each # number and the message at the end should be on its own...

  • Write a telephone lookup PYTHON program. Read a data set of names and telephone numbers from...

    Write a telephone lookup PYTHON program. Read a data set of names and telephone numbers from a file that contains the numbers in random order. Handle lookups by name and also reverse lookups by phone number. Use a binary search for both lookups. Use the following data set: Bob|555-1234 Joe|555-2345 John|555-3456 Luke|555-4567 Mark|555-5678 Matthew|555-6789 The program should prompt the user as follows:       L)ookup Name, Lookup N)umber or Q)uit?       Enter the name:          Or       Enter the Number:...

  • Create a new program in Mu and save it as ps4.3.2.py and take the code below...

    Create a new program in Mu and save it as ps4.3.2.py and take the code below and fix it as indicated in the comments: # Write a function called find_max_sales. find_max_sales will # have one parameter: a list of tuples. Each tuple in the # list will have two items: a string and an integer. The # string will represent the name of a movie, and the integer # will represent that movie's total ticket sales (in millions # of...

  • Create a new program in Mu and save it as ps4.4.1.py and take the code below...

    Create a new program in Mu and save it as ps4.4.1.py and take the code below and fix it as indicated in the comments: # Write a function called "save_leaderboard" that accepts a # single list of tuples as a parameter. The tuples are of the # form (leader_name, score) # The function should open a file called "leaderboard.txt", # and write each of the tuples in the list to a line in the file. # The name and score...

  • Create a new program in Mu and save it as ps4.3.3.py and take the code below...

    Create a new program in Mu and save it as ps4.3.3.py and take the code below and fix it as indicated in the comments: # Imagine you're writing some code for an exercise tracker. # The tracker measures heart rate, and should display the # average heart rate from an exercise session. # # However, the tracker doesn't automatically know when the # exercise session began. It assumes the session starts the # first time it sees a heart rate...

  • Create a new program in Mu and save it as ps2.4.1.py Take the code below and...

    Create a new program in Mu and save it as ps2.4.1.py Take the code below and fix it as indicated in the comments: dividend = 7 divisor = 3 # You may modify the lines of code above, but don't move them! # Your code should work with different values for the variables. # The variables above create a dividend and a divisor. Add # some code below that will print the quotient and remainder # of performing this operation....

  • Make the following modifications/enhancements to Version 0 of the Phonebook application: The phonebook should now contain...

    Make the following modifications/enhancements to Version 0 of the Phonebook application: The phonebook should now contain a first name as well as a last name. The format of the entries in the file should be: last-name first-name phone-number The lookup process now prompts for both a last and a first name A reverse lookup should also be provided, allowing a name to be obtained by supplying the phone number. Rather than continuing until the user signals end-of-file (at the keyboard),...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT