ourList = [
'Polly Ester', '549-5393', 'Bud Wieser', '(218) 477-3928', 'Jack Hammer',
'277-4829', 'Mike Rafone', '345-3453', 'Bill Ding', '218-473-4373',
'Earl Lee Riser', '701-304-8293', 'Tim Burr', '(612) 593-2629', 'Bud',
'(701) 487-8532'
def writeFile(filename, phonebook):
file = open(filename, 'w+')
print('your information is being written in', filename)
stringedList = ', '.join(phonebook)
file.write(stringedList)
def readFile(filename):
phonebook = []
file = open(filename, "r")
for aline in file:
person = aline.split(",")
if person[1][-1] == '/n':
pn = person.pop(1)
person.append(pn[:-1])
phonebook.append(person)
file.close()
return phonebook
print(readFile("phone.txt"))
readFile('phone.txt')
choices = ['exit', 'search phonebook', 'add entry', 'delete entry', 'print phonebook']
def printEnteries(phonebook) :
person = phonebook
print(person)
print("Name Phone")
print("-------------------- --------------")
for word in person:
index = 0
print(word[index])
index += 1
print(word[index])
def main ():
def menu(choices):
for (i, item) in enumerate(choices,start=0):
print(i, item)
userInput = input('choice?: ')
print(userInput)
return userInput
choices = ['exit', 'search phonebook', 'add entry', 'delete entry', 'print phonebook']
phonebook = readFile("phone.txt")
option = menu(choices)
while option !=0:
if option == 1:
print("search phonebook")
elif option == 2:
print("add entry")
elif option == 3:
print("delete entry")
elif option == 4:
print(printEntries(phonebook))
else:
print('not an option')
option = menu(choices)
writeFile("phone02.txt", phonebook)