Question

Write a program that does the following in Python Code: Stores the following three lists: last_name...

Write a program that does the following in Python Code:

  • Stores the following three lists:

last_name = ["Smith", "Jones", "Williams", "Bailey", "Rogers", "Pyle", "Rossington"]

first_name =["Lisa", "Bill", "Jay", "Sally", "Walter","Jake","Gary"]

phone_number =["240-233-1921", "301-394-2745", "571-321-8934", "703-238-3432", "703-947-9987", "301-945-3593", "240-671-3221"]

  • Has a function named combine_lists() that takes in last_names, first_names and phone_numbers as lists and returns a dictionary called phone_book that uses last_name as the key and a list consisting of first_name and phone_number.
  • Has a main function that iterates through the phone_book and prints out its contents.
  • Also, prompt the user to enter a last name and print out the corresponding contact information. When entering the last name of that person, the output should print the first name and phone number of that person.
0 0
Add a comment Improve this question Transcribed image text
Answer #1
def combine_lists(last_names, first_names, phone_numbers):
    contacts = {}
    for i in range(len(last_names)):
        contacts[last_names[i]] = [first_names[i], phone_numbers[i]]
    return contacts


def main():
    last_name = ["Smith", "Jones", "Williams", "Bailey", "Rogers", "Pyle", "Rossington"]
    first_name = ["Lisa", "Bill", "Jay", "Sally", "Walter", "Jake", "Gary"]
    phone_number = ["240-233-1921", "301-394-2745", "571-321-8934", "703-238-3432", "703-947-9987", "301-945-3593",
                    "240-671-3221"]
    contacts = combine_lists(last_name, first_name, phone_number)
    for last_name, data in contacts.items():
        print(data[0] + " " + last_name + ", Number: " + data[1])
    last = input("\nEnter a last name: ")
    if last in contacts:
        print("Phone number of " + contacts[last][0] + ' ' + last + " is " + contacts[last][1])


main()
Add a comment
Know the answer?
Add Answer to:
Write a program that does the following in Python Code: Stores the following three lists: last_name...
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
  • Write a program that does the following in Python Code: Stores the following three lists: last_...

    Write a program that does the following in Python Code: Stores the following three lists: last_name = ["Smith", "Jones", "Williams", "Bailey", "Rogers", "Pyle", "Rossington"] first_name =["Lisa", "Bill", "Jay", "Sally", "Walter","Jake","Gary"] phone_number =["240-233-1921", "301-394-2745", "571-321-8934", "703-238-3432", "703-947-9987", "301-945-3593", "240-671-3221"] Has a function named combine_lists() that takes in last_names, first_names and phone_numbers as lists and returns a dictionary called phone_book that uses last_name as the key and a list consisting offirst_name and phone_number. Has a main function that iterates through the phone_book...

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
ADVERTISEMENT