Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a program as specified below. Testing is progressive, so you get credit as you complete each Part. Part 1 Build a dictionary by inputting,

image text in transcribedimage text in transcribedimage text in transcribed

Write a program as specified below. Testing is progressive, so you get credit as you complete each Part. Part 1 Build a dictionary by inputting, 4 times, a value followed by a key, each on a separate line. Build the dictionary as you go. Do not input all keys and values into 8 separate variables. The key and the value are strings. Do not make more than one dictionary in your program Print 'Part 1 Print the dictionary Print the length of the dictionary. Part 2 Extend the program to: Print "Part 2 Input a key Print the key and the associated value from the dictionary Part 3 Extend the program to: Print 'Part 3 Input two keys Swap their associated values in the dictionary . Print the length of the dictionary. . Print the dictionary Part 4 Extend the program to: Print 'Part 4 Input a key and delete the associated entry from the dictionary. Print the length of the dictionary. Print the dictionary Part 5 Extend the program to: Print 'Part 5 Remove all entries from the dictionary (.e., make it an empty dictionary) Print the length of the dictionary. Print the dictionary Part 1 Example input and output When input is lettuce food Neptune planet neon inert gas Romeo and Juliet Shakespeare play food inert gas Shakespeare play planet Standard output contains Length: 4 Dictionary: {'food': 'lettuce', 'planet': 'Neptune', 'inert gas': 'neon', 'Shakespeare play': "Romeo and Juliet'} Part 5 Example input and output When input is Car Porsche Country Tahiti Person Ghandi Panda Animal Ghandi Tahiti Ghandi Porsche Standard output contains Length: 4 Dictionary: {'Porsche': 'Car', 'Tahiti': 'Country', 'Ghandi': 'Person', 'Animal': 'Panda'} Part 2 Enter the key for the value you want to print: The value for key Ghandi is Person Part 3 Enter first key for swap : Enter second key for swap: Length: 4 Dictionary: {'Porsche': 'Car', 'Tahiti': 'Person', 'Ghandi': 'Country', 'Animal': 'Panda'} Part 4 Enter key to remove: Length: 3 Dictionary: {'Tahiti': 'Person', "Ghandi': 'Country', 'Animal': 'Panda'} Part 5 Length: 0 Dictionary: {} main.py Load default template... 1 You may use the code below to get started or replace with your own if you prefer 2 3 WFUDB = {} 4 5 Part 1: Build and print the dictionary. 6 wfu_val = input ("Enter value: ") 7 wfu_key = input ("Enter key: ") 8 WFU_DB [wfu_key] = wfu_val 9wfu_vai = input ("Enter value: ") 10 wfu_key = input ("Enter key : ") 11 12 print ("Part 1") 13 14 Finish building the dictionary 15 16 uuu Print the dictionary and the length of the dictionary 17 18 m Continue to Part 2 and complete the code. 19 Part 2: Enter a key and print 20 print (Part 2")

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions