Skip to content

Instantly share code, notes, and snippets.

@Blank1611
Created July 17, 2019 08:49
Show Gist options
  • Save Blank1611/ac1ad0dd28b4e57c56f7b771f2ead62d to your computer and use it in GitHub Desktop.
Save Blank1611/ac1ad0dd28b4e57c56f7b771f2ead62d to your computer and use it in GitHub Desktop.
#Phonebook
from IPython.display import clear_output
contacts = {}
def printf(thid):
if len(contacts) == 0:
print("Empty list")
else:
for key,pair in thid.items():
print(key,":",pair)
#drive code
flag = True
while flag:
clear_output()
print("CONTACTS:\n")
print("Choose an operation:\n1. Add\n2. Delete\n3. Search\n4. Display\n5.Update\n")
try:
choice = int(input())
if choice == 1:
contacts[input("Enter a name:").title()] = int(input("Enter the number:"))
print("Entry entered successfully!")
elif choice == 2:
try:
del contacts[input("Enter the name to delete:").title()]
except Exception as e:
print('Error:{} not found!!'.format(e))
else:
print("Successfully deleted!")
elif choice == 3:
name = input("Enter the name to search:").title()
try:
print(name,":",contacts[name])
except Exception as e:
print('Error:{} not found!!'.format(e))
elif choice == 4:
try:
printf(contacts)
except Exception as e:
print('Error:{} !!'.format(e))
elif choice == 5:
try:
contacts[input("Enter a name:").title()] = int(input("Enter the number:"))
except Exception as e:
print('Error:{} not found!!'.format(e))
else:
print("Successfully updated!")
except Exception as e:
print('Error:{} does not exist!!'.format(e))
finally:
flag = input("Would you like to continue ?y/n").lower().startswith('y')
clear_output()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment