# File: ChapterIOFiles/readTest.py """ Files. Design a guessing of type "Want to be a millionaire:". You have a file with one question and 4 answers. File: mytest.txt contains: Who was the first programmer? 1. Ada Lovelave 2. Charles Babbage 3. Alan Turing 4. George Boole Answer. 1 """ from graphics import * import time def main(): win = GraphWin("Readme",300,300) fin = open("Texts/mytest.txt", 'r') #opens file stream object text = fin.readlines() #list text with lines as strings fin.close() x,y = 150,50 #where to start text step = 20 # step y between lines last = text[-1] # last Find last line lastList = last.split() # make list of strings answer = lastList[-1] # find answer as char for i in range(len(text)-1): # does not display last line Text(Point(x,i*step + y),text[i]).draw(win) time.sleep(1) #display slow Text(Point(170,250),"Enter answer using key?").draw(win) #your answer yourans = win.getKey() # input key from user as char if (answer == yourans): msg = "Correct" else: msg = "INCORRECT!" Text(Point(200,270),yourans + " " + msg).draw(win) main()