Created
December 14, 2017 12:33
-
-
Save 200005/2d828661274dab58d4d6898eb81de346 to your computer and use it in GitHub Desktop.
Address Book
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
######## THIS BELOW IS THE FUNCTION/SEARCH ALGORITHM##### | |
class contacts: | |
name = "" | |
phonenumber = 0 | |
def __init__(self, na, num): | |
self.name = na | |
self.phonenumber = num | |
def getName(self): | |
return self.name | |
def getPhone(self): | |
return self.phonenumber | |
def getcontact(self): | |
output = "\n\nYour contact's name is: " + self.name + "\nYour contact's phone number is: " + self.phonenumber + "\n\n" | |
return output | |
contactbook = [] | |
##### THIS IS THE WHILE LOOP WHERE IF STATEMENT CHOICES LIE | |
while True: | |
#####CHOOOSE WHAT YOU WANNA DO###### | |
choice = input("\n\nWelcome to your contact book, what would you like to do?\n" | |
"1) To search\n" | |
"2) To add.\n" | |
) | |
if choice == "1" and len(contactbook) > 0: | |
found = False | |
lookfor = input("\nEnter your search?\nPlease input:\n" | |
"1) Name\n" | |
"2) Phonenumber\n" | |
) | |
if lookfor == "1": | |
inName = input("Please input your contact's name:") | |
###SEARCH ALGORITHM | |
for x in range(0, len(contactbook)): | |
if contactbook[x].getName() == inName: | |
print(contactbook[x].getcontact()) | |
found = True | |
break | |
elif lookfor == "2": | |
###SEARCH ALGORITHM | |
inNum = input("Please input your contact's number:") | |
for x in range(0, len(contactbook)): | |
if contactbook[x].getPhone() == inNum: | |
print(contactbook[x].getcontact()) | |
found = True | |
break | |
if (not found): | |
print("Your contact was not found. Please try again.") | |
elif choice == "2": | |
nam = input("\nPlease input a name: ") | |
number = input("\nPlease input a phone number: ") | |
contactbook.append(contacts(nam, number)) | |
else: | |
print("invalid choice") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment