close the file file close( ht(screen exitonclick(print("program execution completed " if __name__ ="__main__"main(when reading file with multi-line recordsa while loop is needed notice that on line the first line of the first record is read prior to the while loop for the body of the while loop to executethe condition must be tested prior to executing the loop reading line prior to the while loop is necessary so we can check to see if the file is empty or not the first line of every other record is read at the end of the while loop on line this is the loop and half pattern the first line of the first record is read before the while loop while the first line of every other record is read inside the while loop just before the end when the condition becomes falsethe while loop terminates the abstract pattern for reading multi-line records from file is shown in sect there are certainly other forms of this pattern that can be usedbut memorizing this pattern is worth-while since the pattern will work using pretty much any programming language pattern for reading multi-line records from file first the file must be opened file open(filename" " read the first line of the first record in the file of coursefirstline should be called something that makes sense in your program firstline file readline(strip( while firstline !""read the rest of the record secondline file readline(strip(thirdline file readline(strip( then process the record this will be determined by the program you are writing print(firstlinesecondlinethirdline finallyfinish the loop by reading the first line of the next record to set up for the next iteration of the loop firstline file readline(strip( it' good idea to close the filebut it will be automatically closed when your program terminates file close(this copy belongs to 'acha