(calle iry") input argume The function aims to create a dictionary, to do that, the function needs to ask the use to enter how many key-value pair to create. Then the user needs to enter (input0) each key-value pair using the keyboard input. The function needs to take the first elements as a key, the second element entered as a value and add it to the "dictionary".

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
answer this question in python
Exercise :
1. Create a function (called "create_a_dictionary") with no input argument.
The function aims to create a dictionary, to do that, the function needs to ask the user
to enter how many key-value pair to create.
Then the user needs to enter (input0) each key-value pair using the keyboard input.
The function needs to take the first elements as a key, the second element entered as
a value and add it to the
"dictionary".
The function must return a dictionary.
2. Create a function (called "reverse_dictionary") that needs a dictionary as input
and reverses it,
meaning that the values become the keys and vice-versa and returns the reverse
dictionary in a
new variable.
3. Testing your code:
Run create_a_dictionary and generate a dictionary with 5 key:value pairs
Print the dictionary
Reverse it using "'reverse_dictionary" function that you have created
Print the reversed dictionary
Transcribed Image Text:Exercise : 1. Create a function (called "create_a_dictionary") with no input argument. The function aims to create a dictionary, to do that, the function needs to ask the user to enter how many key-value pair to create. Then the user needs to enter (input0) each key-value pair using the keyboard input. The function needs to take the first elements as a key, the second element entered as a value and add it to the "dictionary". The function must return a dictionary. 2. Create a function (called "reverse_dictionary") that needs a dictionary as input and reverses it, meaning that the values become the keys and vice-versa and returns the reverse dictionary in a new variable. 3. Testing your code: Run create_a_dictionary and generate a dictionary with 5 key:value pairs Print the dictionary Reverse it using "'reverse_dictionary" function that you have created Print the reversed dictionary
Expert Solution
Program code:

def create_a_dictionary(): # Defining method create_a_dictionary()
    Dictionary={} # Creating empty dictionary
    n=int(input("How many key-value pairs do you want to create? ")) #Taking input for number of key value pairs
    print("Enter",n,"key value pairs:") #Printing statement
    for i in range(n): #Loop to take input for n number of key value pairs
        List=input().split() # Storing user input in List
        Dictionary[List[0]]=List[1] #Adding element to dictionary
    return Dictionary # Returning Dictionary
        
def reverse_dictionary(Dictionary): # Defining method reverse_dictionary() with Dictionary as input
    return dict(zip(Dictionary.values(),Dictionary.keys())) # Returning Dictionary by swapping key value pairs.

Dictionary=create_a_dictionary() # Creating dictionary by calling create_a_dictionary()
ReverseDict=reverse_dictionary(Dictionary) # Reversing dictionary by calling reverse_dictionary()
print("Initial dictionary is: ",Dictionary) # Printing initial dictionary
print("Dictionary after reversal is:",ReverseDict) # Printing reversed dictionary

steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY