Oh do I need some serious help! lol. I'm working on a phone book in python. For some reason when I select the option, enter....say....the last name, even though it's on the file that my program is reading it tells me that it's not there.
Can somebody please look at my program, and help point out where I'm going wrong or what I'm missing? I'm rather new at this, so be gentle! ;-)
def main(): #Set up contact lists.
myList = []
option = displayMenu()
while option != '4': # Set up menu choices.
if option == '1':
getLastName(myList)
elif option == '2':
getFirstName(myList)
elif option == '3':
getPhoneNumber(myList)
option = displayMenu()
print "\nThank you for looking.\n\n"
def displayMenu(): # Display menu options/Data Validation.
choice = '0'
while choice != '1' and choice != '2' and choice != '3' \
and choice != '4':
print """\n\nPlease select an option:
1. Search by Last Name:
2. Search by First Name:
3. Search by Phone Number:
4. End search."""
choice = raw_input("Enter option --> ")
# Data validation
if choice != '1' and choice != '2' and choice != '3' \
and choice != '4':
print "Invalid option. Please select again."
return choice
# Opening and reading file into a three arrays in a loop.
entries = "C:\Documents and Settings\Brenda\Desktop\
CSCD 110 Assignments\entries.txt"
fileInput = open("entries.txt", "r")
myList = fileInput.read()
count = 0
for myString in fileInput:
myString = myString.strip()
myString = mystring. lower()
myNum = count % 3
if myNum == 0:
lastName.append(myString)
elif myNum == 1:
firstName.append(myString)
elif myNum == 2:
phoneNumber.append(myString)
count = count + 1
fileInput.close()
# Set up menu choice for looking up last name.
def getLastName(lastList):
lastName = raw_input("Last name to lookup --> ").strip() .lower()
pointer = 0
if lastName in lastList:
while True:
try:
pointer = lastName.index(lastName, pointer)
print lastName[pointer].title(),
pointer = pointer + 1
except:
break
else:
print "No entry found for " + name.title()
# Set up menu choice for looking up first name.
def getFirstName(firstList):
firstName = raw_input("First name to lookup --> ").strip() .lower()
pointer = 0
if firstName in firstList:
while True:
try:
pointer = firstName.index(firstName, pointer)
print firstName[pointer].title(),
pointer = pointer + 1
except:
break
else:
print "No entry found for " + name.title()
# Set up menu choice for looking up phone number.
def getPhoneNumber(phoneList):
phoneNumber = raw_input("Phone number to lookup --> ").strip() .lower()
pointer = 0
if phoneNumber in phoneList:
while True:
try:
pointer = phoneNumber.index(phoneNumber, pointer)
print phoneNumber[pointer].title(),
pointer = pointer + 1
except:
break
else:
print "No entry found for " + phoneNumber.title()
main()