I posted a question earlier today that was downvoted heavily. Long story short you all did me a favor because I worked through it and figured it out myself (thank you). With that being said I'm still confused a bit on how it worked. I'd really like to have a 100% understanding of why my code is working.
My instructor gave the class a piece of code to give us some lead into the assignment.
name = input("Please enter the phone number you would like to search for: ")
pointer = 0
if name in phone:
pointer = phone.index(name,pointer)
pointer += 1
print("No entry found for " + name)
myFile = open('entries.txt','r')
lName = 
fName = 
phone = 
count = 1
for line in myFile:
line = line.strip()
line = line.lower()
if count % 3 == 1:
elif count % 3 ==2:
count += 1
pointer is some random variable name. It points to a character index in the string.
If I understand the logic of the code, it could also be written like this
def lookPhone(lName,fName,phone): number = input("Please enter the phone number you would like to search for: ") index = 0 # Start at the beginning of the list # Loop while we have data while name in phone: # Try to print the elements from the lists try: ''' Find the position of 'name' in 'phone' starting from 'index' position throws 'ValueError' if not found ''' index = phone.index(name,index) print(lName[index].title(),fName[index].title()) print(phone[index]) except ValueError: break # Move to the next position index += 1 else: print("No entry found for " + name)