Final answer:
To perform the given operations on a dictionary of friends' names and phone numbers, you can write a program in Python.
The program will allow you to display the name and phone number of all friends, add new friends, delete existing friends, modify phone numbers, check if a friend is present, and display the dictionary in sorted order of names.
Step-by-step explanation:
To write a program that performs the given operations on a dictionary of friends' names and phone numbers, you can use a programming language such as Python.
Here is an example program that accomplishes the task:
friend_dictionary = {}
# a) Display the name and phone number of all your friends
for friend, phone_number in friend_dictionary.items():
print(friend, phone_number)
# b) Add a new key-value pair in this dictionary and display the modified dictionary
new_friend = input('Enter the name of a new friend: ')
new_phone_number = input('Enter the phone number of the new friend: ')
friend_dictionary[new_friend] = new_phone_number
print(friend_dictionary)
# c) Delete a particular friend from the dictionary
delete_friend = input('Enter the name of the friend to delete: ')
del friend_dictionary[delete_friend]
# d) Modify the phone number of an existing friend
existing_friend = input('Enter the name of the friend whose phone number you want to modify: ')
new_phone_number = input('Enter the new phone number: ')
friend_dictionary[existing_friend] = new_phone_number
# e) Check if a friend is present in the dictionary or not
check_friend = input('Enter the name of the friend to check: ')
if check_friend in friend_dictionary:
print('Friend found.')
else:
print('Friend not found.')
# f) Display the dictionary in sorted order of names
for friend in sorted(friend_dictionary):
print(friend, friend_dictionary[friend])