Untitled
unknown
plain_text
2 years ago
3.8 kB
7
Indexable
Contacts = [["" for _ in range(3)] for _ in range(100)] # TO FIX - Question says to put column 1 contact name: last name, first name and column 2 - telephone number
CurrentSize = 0
#TO FIX (Optional) - Password check is not required
Continue = True
while Continue:
print("Please enter a delete password, this will be require whenever you wish to clear your contact array.")
Password = input()
print("")
print("Are you sure? This cannot be change once set.")
print("Y/N")
pchoice = input()
if pchoice == "Y" or pchoice == "y":
Continue = False
Continue = True
while Continue:
print("")
print("Please select an option:")
print("1. Enter new contact details")
print("2. Display all the contact details")
print("3. Delete all the contact details")
print("4. Exit the software")
choice = input()
while not choice.isdigit() or (int(choice) < 1 or int(choice) > 4):
print("")
print("Please select from the above.")
choice = input()
print("")
if choice == "1":
#TODO: allow up to max of 5 new contacts to array at one time
#TODO: do not allow more than 100 contacts in total
print("")
print("Please enter the last name of the contact.")
Contacts[CurrentSize][0] = input()
print("")
print("Please enter the first name of the contact.")
Contacts[CurrentSize][1] = input()
print("")
print("Please enter his/her telephone number.")
Contacts[CurrentSize][2] = input()
print("")
CurrentSize = CurrentSize + 1
print("You know what you have done.")
if choice == "2":
if CurrentSize == 0:
print("But there is no one here. ")
if CurrentSize == 1:
print("There is only 1 contact detail here.")
if CurrentSize >= 2:
print("There are currently ",(CurrentSize)," contact details here.")
print(Contacts)
print("")
print("Would you like to sort them?")
print("Y/N")
schoice = input()
if schoice == "Y" or schoice == "y":
Sort = True
while Sort == True:
Flag = False
for i in range(1, CurrentSize):
if Contacts[i][0] < Contacts[i-1][0]:
Flag = True
Temp1 = Contacts[i][0]
Temp2 = Contacts[i][1]
Contacts[i][0] = Contacts[i-1][0]
Contacts[i][1] = Contacts[i-1][1]
Contacts[i-1][0] = Temp1
Contacts[i-1][1] = Temp2
if not Flag:
break
print(Contacts)
if choice == "3":
print("This will completely clear out the entire list of contacts, are you sure?")
print("Y/N")
dchoice = input()
if dchoice == "Y" or dchoice == "y":
print("")
print("This action cannot be undo, are you really sure about it?")
print("Y/N")
d2choice = input()
print("")
if d2choice == "Y" or d2choice == "y":
print("Please enter your delete password.")
attempt = input()
if attempt == Password:
Contacts = [["" for _ in range(3)] for _ in range(100)]
CurrentSize = 0
print("")
print("Deleted.")
if not attempt == Password:
print("")
print("Incorrect password.")
if choice == "4":
print("I see, have a great day.")
Continue = False
Sort = True
while Sort == True:
Editor is loading...
Leave a Comment