Question: Write and test a Python program that begins with an empty dictionary friends_colors. Then ask the user how many friends they have, and make this

Write and test a Python program that begins with an empty dictionary friends_colors. Then ask the user how many friends they have, and make this the value a variable number_of_friends. Then set up a while loop and loop this many times. Each time through the loop, have the user enter some friend's name, and make this the value of a variable name. Also prompt the user for the friend's favorite color, and make this the value of a variable color. Then arrange for the dictionary to be updated to include this new information. Simply use name as the key (index) and use the square bracket notation to set the corresponding value equal to color. Do that inside the loop. After the loop, use print(friends_colors)to display the entire dictionary (as a list of key : value pairs). Test that all this works before continuing.

Then, after all that, add another while loop, that loops exactly three times, and each time prompts the user for the name of a friend. If that name has been included as a key for the dictionary, then display a message like this:

so-and-so's favorite color is whatever.

Of course the friend's name should take the place of so-and-so, and their favorite color should take the place of whatever. However, if the name given is not a valid key, then display a message like this instead:

so-and-so is not your friend!

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!