text files directories say your program opens filelike belows open'file txt 'read(the file is assumed to be in the same directory as your program itself if it is in different directorythen you need to specify thatlike belows open' :/users/heinold/desktop/file txt 'read( writing to files there are also several ways to write to files we will look at one way here we will be writing to file called writefile txt open'writefile txt '' 'print'this is line 'file=fprint'this is line 'file=ff close(we first have to open the file that is what the first line doeswith the 'windicating that we want to be able to write to the file python creates what is called file object to represent the fileand we give that object the name this is what we use to refer to the file to write to the filewe use the print statement with the optional file argument that specifies the file to write to when we are done writingwe should close the file to make sure all of our changes take be careful here because if writefile txt already existsits contents will be overwritten examples example write program that reads list of temperatures from file called temps txtconverts those temperatures to fahrenheitand writes the results to file called ftemps txt file open'ftemps txt '' 'temperatures [line strip(for line in open'temps txt ')for in temperaturesprint(int( )* / + file=file file close(example in section we wrote simple quiz game the questions and answers were both contained in lists hard-coded into the program instead of thatwe can store the questions and answers in files that wayif you decide to change the questions or answersyou just have to change their files moreoverif you decide to give the program to someone else who doesn' know