Advertisement
Arcot

ch5 ex4 contacts

Oct 16th, 2021 (edited)
226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.77 KB | None | 0 0
  1. response = 1
  2. contacts = []
  3. while response != 0:
  4.     response = int(input("Enter:\n1. to add\n2. to remove\n3. to print\n0. to exit\n"))
  5.     if response == 1:
  6.         name = input("Enter the name you want to add: ")
  7.         if name in contacts:
  8.             print("Name already present in contacts")
  9.         else:
  10.             contacts.append(name)
  11.             print("Name added successfully")
  12.     elif response == 2:
  13.         name = input("Enter the name you want to remove: ")
  14.         if name not in contacts:
  15.             print("Name not present in contacts")
  16.         else:
  17.             contacts.remove(name)
  18.             print("Name removed successfully")
  19.     elif response == 3:
  20.         contacts.sort()
  21.         for name in contacts:
  22.             print(name)
  23.         print()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement