Question

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 and prints out its contents. Also, prompt the user to enter a last name and print out the corresponding contact information.
0 0
Add a comment Improve this question Transcribed image text
Answer #1
def combine_lists(last_names, first_names, phone_numbers):
    phone_book = {}
    for i in range(len(last_names)):
        phone_book[last_names[i]] = [first_names[i], phone_numbers[i]]
    return phone_book


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"]
    phone_book = combine_lists(last_name, first_name, phone_number)
    for l_name, value in phone_book.items():
        print(value[0] + " " + l_name + ", Number: " + value[1])
    last = input("Enter a last name: ")
    if last in phone_book:
        print("Number of " + last + " is " + phone_book[last][0])


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_...
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_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...

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