I am new at python, im trying to write a code to print several lines after an if statement.
for example, I have a file "test.txt" with this style:
Hello how are you? fine thanks how old are you? 24 good how old are you? i am 26 ok bye. Hello how are you? fine how old are you? 13 good how old are you? i am 34 ok bye. Hello how are you? good how old are you? 17 good how old are you? i am 19 ok bye. Hello how are you? perfect how old are you? 26 good how old are you? i am 21 ok bye. so I want to print one line after each "how old are you" my code is like this:
fhandle=open('test.txt') for line in fhandle: if line.startswith('how old are you?') print(line) /*** THIS IS THE PROBLEM I want to print next line after how old are you ( maybe print two lines after "how old are you" )