0

You are given a multi line text file and are asked to input a word that you want to find and the output should tell the user what line the word is located and at what character the word is at ie. (abcd c is the second character starting from zero).

f='Abbott: You throw the ball to first base.\nCostello: Then who gets it?\nAbbott: Naturally.\nCostello: Naturally.'
pat=raw_input('Enter a Pattern')
    lines=f.split("\n")
    for i,line in enumerate(lines):
        if pat in line:
            print('{} found on line number {} at character {}'.format(pat, i+1,f.find(pat)))

I can't figure out how to do the print statement multiple times if the word is repeated also I cant seem to get the correct character

User0123456789
  • 760
  • 2
  • 10
  • 25
  • 1
    This smells of homework for some reason. – SMS von der Tann Apr 18 '16 at 17:44
  • http://stackoverflow.com/questions/3873361/finding-multiple-occurrences-of-a-string-within-a-string-in-python this is what you are looking for probably to find a pattern in a string multiple times. – Lafexlos Apr 19 '16 at 12:55

0 Answers0