Advertisement
Guest User

Untitled

a guest
Mar 19th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. phonebook ={}
  2.  
  3. with open("phonebook.txt", "w+") as file:
  4. display = file.readlines()
  5. file.seek(0)
  6.  
  7.  
  8. def Menu():
  9. print("\nWelcome to the phonenbook")
  10. print("----------------------------")
  11. print("1: delete a contact:\n")
  12. print("2: Search contact by name:\n")
  13. print("3: Display all contacts:\n")
  14. print("4: Add a contact:\n")
  15. print("-----------------------------")
  16. choice = input(str("choose from menu"))
  17. if choice == "4":
  18. ADD_to()
  19. elif choice =="3":
  20. Display()
  21.  
  22. elif choice == "2":
  23. search()
  24.  
  25. elif choice =="1":
  26. delete_con()
  27.  
  28.  
  29. def ADD_to():
  30. name = input("enter a name to store")
  31. phonenumber = input("enter phone number to save")
  32. phonebook.setdefault(name,phonenumber)
  33. with open("phonebook.txt", "w+") as file:
  34. file.seek(0)
  35. for keys,values in (phonebook.items()):
  36. display = file.writelines(keys + ":")
  37. display = file.writelines(values)
  38. return Menu()
  39.  
  40. def Display():
  41. for contact in phonebook:
  42. print(contact)
  43.  
  44.  
  45. def Delete_con():
  46. with open("phonebook.txt", 'r+') as file:
  47. content = file.readlines()
  48. phonebook.popitem()
  49.  
  50.  
  51.  
  52.  
  53. Menu()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement