python - Converting txt file to list and returning line after user input search -
i'm trying have user input telephone number, program open text file, convert list, search list , if phone number found return rest of line (which contains address phone number.
i can return either "phone number not found" or line every single line end output this:
phone number not found phone number not found 0121 254132 18 springfield road phone number not found phone number not found
for line in phonenumbers: if number in line: print (line) else: print ("phone number not found")
i know it's because i've put line in phonenumbers don't know how not every line.
try following:
for line in phonenumbers: if number in line: print (line) break else: print ("phone number not found")
the else
part of for
loop , execute if didn't break
out of for
loop.
Comments
Post a Comment