Following is as far as I can go, the problem is it is breaking after the first find, whereabouts I know there are additional matches in the txt file. I think I might need to replace the IF with a WHILE, which I have tried but keep getting errors, and am unable to work it out.
Expand|Select|Wrap|Line Numbers
- print"\nSEARCHING NUMBERS"
- print "\nPlease Enter the Number 1, 2, 3, 4 or 5."
- text_file = open("read_it.txt", "r")
- word = raw_input("Type the Number you want to check: ") word = word.upper()
- print "\nnumber."
- for lines in text_file:
- # if the line does not contain the typed number
- # then continue to the next line
- if ''.join(lines).find(word) == -1:continue
- print lines
- break
- else:
- print "Not found" # Executed whenever break above is NOT executed
- print raw_input("\n\nPress the enter key to exit.")
- text_file.close()
L :)