Advertisement
Guest User

Untitled

a guest
Oct 15th, 2019
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.31 KB | None | 0 0
  1. # fnc that creates a contact w/ the provided info.
  2. def add_contact(contacts, first_name, last_name, email, phone_number, age):
  3. contacts[first_name + " " + last_name] = {}
  4. contacts[first_name + " " + last_name]['first_name'] = first_name
  5. contacts[first_name + " " + last_name]['last_name'] = last_name
  6. contacts[first_name + " " + last_name]['email'] = email
  7. contacts[first_name + " " + last_name]['phone_number'] = phone_number
  8. contacts[first_name + " " + last_name]['age'] = age
  9.  
  10.  
  11. # fnc that checks if a contact exsits.
  12. def has_contact(contacts, first_name, last_name):
  13. if (first_name + " " + last_name) in contacts:
  14. return True
  15. else:
  16. return False
  17.  
  18.  
  19. # fnc that gets a contacts age.
  20. def get_contact_age(contacts, first_name, last_name):
  21. if has_contact(contacts, first_name, last_name):
  22. return contacts[first_name + " " + last_name]["age"]
  23. else:
  24. return None
  25.  
  26.  
  27. # fnc that gets a contacts email.
  28. def get_contact_email(contacts, first_name, last_name):
  29. if has_contact(contacts, first_name, last_name):
  30. return contacts[first_name + " " + last_name]["email"]
  31. else:
  32. return None
  33.  
  34.  
  35. # fnc that gets a contacts number.
  36. def get_contact_phone_number(contacts, first_name, last_name):
  37. if has_contact(contacts, first_name, last_name):
  38. return contacts[first_name + " " + last_name]["phone_number"]
  39. else:
  40. return None
  41.  
  42.  
  43. # fnc that returns a contact in a string.
  44. def get_contact_as_str(contacts, first_name, last_name):
  45. if has_contact(contacts, first_name, last_name):
  46. email = get_contact_email(contacts, first_name, last_name)
  47. phone_number = get_contact_phone_number
  48. (contacts, first_name, last_name)
  49. age = get_contact_age(contacts, first_name, last_name)
  50. str = first_name + " " + last_name + "\n" + "E-mail: " + email
  51. + "\n" + "Phone#: " + phone_number + "\n" + "Age: " + age
  52. return str
  53. else:
  54. return ("No contact data for " + first_name + " "
  55. + last_name + " found")
  56.  
  57.  
  58. # fnc that allows you to update any field of a contact.
  59. def update_info(contacts, first_name, last_name, what, value):
  60. if has_contact(contacts, first_name, last_name):
  61. contacts[first_name + " " + last_name][what] = value
  62. return True
  63. else:
  64. return False
  65.  
  66.  
  67. # fnc that updates the contacts age using the update_info fnc.
  68. def update_contact_age(contacts, first_name, last_name, age):
  69. return update_info(contacts, first_name, last_name, "age", age)
  70.  
  71.  
  72. # fnc that updates the contacts email using the update_info fnc.
  73. def update_contact_email(contacts, first_name, last_name, email):
  74. return update_info(contacts, first_name, last_name, "email", email)
  75.  
  76.  
  77. # fnc that updates the contacts phone using the update_info fnc.
  78. def update_contact_phone_number(
  79. contacts,
  80. first_name,
  81. last_name,
  82. phone_number,
  83. ):
  84. return update_info(contacts, first_name, last_name, 'phone_number',
  85. phone_number)
  86.  
  87.  
  88. # fnc that removes a contact.
  89. def remove_contact(contacts, first_name, last_name):
  90. if has_contact:
  91. str = contacts[first_name + " " + last_name]
  92. del contacts[first_name + " " + last_name]
  93. return str
  94. else:
  95. return None
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement