Skip to content

Commit 3a87781

Browse files
[Shubham] Add: remove_contact function for deleting contact.
1 parent 5cb1235 commit 3a87781

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

AddressBook_Service.py

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,14 @@ def add_contact(self):
4545

4646

4747
def fetch_contact(self,first_name):
48+
"""
49+
Description :
50+
This function fetches contact from contact list uing first name.
51+
Parameters :
52+
first_name : first name of the contact to remove.
53+
Returns :
54+
contact : contact from contacts list.
55+
"""
4856
for contact in self.contacts:
4957
if contact.first_name == first_name:
5058
return contact
@@ -79,7 +87,28 @@ def update_contact(self,first_name):
7987
else:
8088
input("Contact not found. Hit enter to continue")
8189

82-
# display address Book
90+
91+
# remove contact from address Book
92+
def remove_contact(self,first_name):
93+
"""
94+
Description :
95+
This function checks if the first name in present in contact
96+
if it is present, take the inputs from user again ,find the index number and update the contact.
97+
Parameters :
98+
self : self.contacts list.
99+
Returns :
100+
none
101+
prints update message.
102+
"""
103+
contact = self.fetch_contact(first_name)
104+
if contact:
105+
self.contacts.remove(contact)
106+
print("Contact removed successfully")
107+
else:
108+
input("Contact not found. Hit enter to continue")
109+
110+
111+
# display contacts from address Book
83112
def display_contact(self):
84113
"""
85114
Description :

0 commit comments

Comments
 (0)