0
You visited us 0 times! Enjoying our articles? Unlock Full Access!
Question

Write a program to input your friends names and their Phone Numbers and store them in the dictionary as the key-value pair. Perform the following operations on the dictionary:
a) Display the name and phone number of all your friends
b) Add a new key-value pair in this dictionary and display the modified dictionary
c) Delete a particular friend from the dictionary
d) Modify the phone number of an existing friend
e) Check if a friend is present in the dictionary or not
f) Display the dictionary in sorted order of names

Solution
Verified by Toppr

n = int(input("Enter how many names you want to enter: "))
# initialize empty dictionary
names={}
for i in range(n):
name=input("Enter name of friend: ")
number=input("Enter phone number: ")
names[name]=number #add name number to dictionary
print(names)
names["Arun"]="9877666234" #add new item
print("Modified dictionary ",names)
del names["Arun"] #delete an item
for name in names: #modify first key value
names[name] = "9456356344"
break
print("Amit" in names)
print("dictionary in sorted order")
for i in sorted (names) : #sort the dictionary
print((i, names[i]), end =" ")

Was this answer helpful?
9
Similar Questions
Q1
Write a program to input your friends’ names and their Phone Numbers and store them in the dictionary as the key-value pair. Perform the following operations on the dictionary:
a) Display the name and phone number of all your friends
b) Add a new key-value pair in this dictionary and display the modified dictionary
c) Delete a particular friend from the dictionary
d) Modify the phone number of an existing friend
e) Check if a friend is present in the dictionary or not
f) Display the dictionary in sorted order of names
View Solution
Q2
Write a Python program to find the highest 2 values in a dictionary.
View Solution
Q3
If the following words are written in a dictionary. Which word comes at second number in the dictionary?
View Solution
Q4
The letters of word OUGHT are written in all possible orders and these words are written out as in a dictionary. Find the rank of the word TOUGH in this dictionary.
View Solution
Q5
From 6 different novels and 3 different dictionaries, 4 novels and 1 dictionary are to be selected and arranged in a row on a shelf so that the dictionary is always in the middle. Then the number of such arrangements is
View Solution