In: Computer Science
Implement a python program in file named tarvel.py. Create an empty dictionary named responses. Implement while loop to take in user's name and desired destination for as long as there are user inputs. Prompt user to input yes to continue and no to quit. Prompt for user's name. Receive the name into the program and save it as the value of name variable. Prompt user for their desired vacation destination. Receive response and save it as the value of a response variable. Send the name and response to your response dictionary as key-value pair. Once all inputs are in the program, print each poll participant's name and desired vacation destination. Use for loop to run through all key-pairs in the dictionary. Pay attention to your output. Print the dictionary to show the key-value pairs. Test program with 3 - 5 key value pairs.
Thanks for the question. Here is a simple program. I have added enough comments so that you can understand it precisely.
Let me know for any doubts please : )
------------------------------------------------------------------------------------------------------------------------------------------------------------------------
# create empty dictionary
responses={}
while True:
#get name and destionation
name=input('Enter name:
')
response=input('Enter desired vacation
destination: ')
# check if the name already exists in the
dictionary
if name
in responses.keys():
# print messsage that the
name already exist dont add this entry
print('There is already an entry by that
name.')
continue
# if the name is new add it in
dictionary
else:
responses[name.title()]=response
# ask user if want to continue
addmore = input('Input yes to
continue no to quit: ')
if
addmore.lower()=='no':break
# print the name and destionation as key value pair
for name,response in
responses.items():
print('Name: {} Destination:
{}'.format(name,response))