Page 234 - Information_Practice_Fliipbook_Class11
P. 234
phone = input("Enter friend's phone number: ")
friendsDict[name] = phone
print(f"\n'{name}' added. Updated dictionary:")
for name, phone in friendsDict.items():
print(f"{name}: {phone}")
elif choice == 3:
deleteName = input("Enter the name to delete from the dictionary: ")
if deleteName in friendsDict:
del friendsDict[deleteName]
print(f"\n'{deleteName}' deleted. Updated dictionary:")
for name, phone in friendsDict.items():
print(f"{name}: {phone}")
else:
print(f"\n'{deleteName}' not found in the dictionary.")
elif choice == 4:
modifyName = input("Enter the name to modify the phone number: ")
newPhone = input("Enter the new phone number: ")
if modifyName in friendsDict:
friendsDict[modifyName] = newPhone
print(f"\n'{modifyName}' phone number modified. Updated dictionary:")
for name, phone in friendsDict.items():
print(f"{name}: {phone}")
else:
print(f"\n'{modifyName}' not found in the dictionary.")
elif choice == 5:
checkName = input("Enter the name to check in the dictionary: ")
if checkName in friendsDict:
print(f"\n'{checkName}' is present in the dictionary with phone number:
{friendsDict[checkName]}")
else:
print(f"\n'{checkName}' is not found in the dictionary.")
elif choice == 6:
sorted_dict = dict(sorted(friendsDict.items()))
print("\nDictionary sorted by names:")
for name, phone in sorted_dict.items():
print(f"{name}: {phone}")
elif choice == 7:
print("Exiting the program.")
break
else:
print("Invalid choice. Please enter a number between 1 and 7.")
220 Touchpad Informatics Practices-XI

