question archive THE ASSIGNMENT: find() returns a single instance of Contact
Subject:Computer SciencePrice: Bought3
THE ASSIGNMENT:
find() returns a single instance of Contact. However, there can be multiple instance of Contacts that match the same first/last name. One way to address the problems is to modify find() (and other code necessary) such that it returns a list of Contacts in such case and print them out (the order in the list is not important). Another way is to add a BY_FIRST_AND_LAST_NAME value to the by parameter and an additional menu item to find by first and last name (don't worry about multiple Contacts matching the first and last name in this case). If you choose this, please put a docstring in find() describing your approach.
With either approach, make sure that, if there's only one match, a single instance of Contact is returned as described in the non-extra-credit parts of the assignment. In other words, any extra-credit work must not change how the normal, non-extra-credit code behaves.
MY CODE: I've really unsure how to go about this.
def find(self, name, by): """ Find a contact by the given name """ if by == self.BY_LAST_NAME: for contact in self.contacts: if contact.last_name == name: return contact else: for contact in self.contacts: if contact.first_name == name: return contact return None