Page 455 - Computer Science V2.0 Class 11
P. 455

print(f"\n'{name}' phone number modified. Updated dictionary:")
                                  displayFriends(myDict)
                              else:
                                  print(f"\n'{name}' not found in the dictionary.")

                          def checkFriend(myDict, name):
                              if name in myDict:
                                   print(f"\n'{name}' is present in the dictionary with phone number: {myDict[name]}")
                              else:
                                  print(f"\n'{name}' is not found in the dictionary.")

                          def displaySorted(myDict):
                              sorted_dict = dict(sorted(myDict.items()))
                              print("\nDictionary sorted by names:")
                              displayFriends(sorted_dict)

                          def main():
                              friendsDict = {}

                              while True:
                                  print("\nMenu:")
                                  print("1. Display Friends")
                                  print("2. Add Friend")
                                  print("3. Delete Friend")
                                  print("4. Modify Phone")
                                  print("5. Check Friend")
                                  print("6. Display Sorted Dictionary")
                                  print("7. Exit")

                                  choice = int(input("Enter your choice (1-7): "))

                                  if choice == 1:
                                      displayFriends(friendsDict)
                                  elif choice == 2:
                                      name = input("Enter friend's name: ")
                                      phone = input("Enter friend's phone number: ")
                                      addFriend(friendsDict, name, phone)
                                  elif choice == 3:
                                      deleteName = input("Enter the name to delete from the dictionary: ")
                                      deleteFriend(friendsDict, deleteName)
                                  elif choice == 4:
                                      modifyName = input("Enter the name to modify the phone number: ")
                                      newPhone = input("Enter the new phone number: ")
                                      modifyPhone(friendsDict, modifyName, newPhone)
                                  elif choice == 5:
                                      checkName = input("Enter the name to check in the dictionary: ")
                                      checkFriend(friendsDict, checkName)
                                  elif choice == 6:
                                      displaySorted(friendsDict)
                                  elif choice == 7:
                                      print("Exiting the program.")


                                                                                                        Dictionaries  441
   450   451   452   453   454   455   456   457   458   459   460