Advertisement
ZEdKasat

Chapter 5 Contacts

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