Note: Multiple choice questions may be another option to add to your code. See ask-multiple-choice-question.txt for how to ask the player a multiple choice question. For a good example of asking a question, see cheryls-math-game.zip. ADD STRING TO IMPORT LIST: Add 'string' to the import list at the top of the file that contains the class you will use to ask questions. BASIC QUESTION FUNCTION: Add the following function to the class you will use to ask questions. It will ask the user the question, wait for the user to type in their question, and then return whether the user's answer was correct (True or False). This function is limited to taking lower case letters and numbers from the user. def ask_question(self,question,correct_answer): answered_correctly = False activity_completed = False user_answer = "" while not activity_completed: for event in pygame.event.get(): if event.type == pygame.QUIT: sys.exit() elif event.type == pygame.KEYDOWN: if event.key == K_RETURN: activity_completed = True answered_correctly = (string.lower(user_answer) == string.lower(str(correct_answer))) elif event.key == K_BACKSPACE: user_answer = user_answer[0:-1] elif event.key in range(256): user_answer += chr(event.key) # Draw everything to the screen self.screen.blit(self.background, (0, 0)) # Draw the question font = pygame.font.Font(None, 30) text = font.render(question, 1, (0,0,0)) textrect = text.get_rect() textrect.centerx, textrect.centery = self.area.centerx,self.area.centery self.screen.blit(text, textrect) # Give instructions for submitting the answer font = pygame.font.Font(None, 30) text = font.render("Press Enter to submit your answer.", 1, (0,0,0)) textrect = text.get_rect() textrect.centerx, textrect.centery = self.area.centerx,self.area.centery textrect.centery += 100 self.screen.blit(text, textrect) # Draw the user's input font = pygame.font.Font(None, 30) text = font.render(user_answer, 1, (0,0,255)) textrect = text.get_rect() textrect.centerx = self.area.centerx textrect.centery = self.area.centery + 200 self.screen.blit(text, textrect) pygame.display.flip() return answered_correctly Change the text drawing to customize it for your game. For example, if you want the user's input to be left-justified, use 'textrect.left = 10' instead of 'textrect.centerx = self.area.centerx'. If you want it to be right-justified (in the case of a math problem), use 'textrect.right = 500' Note: If you are using the PracticeDrill template, you can use this for your play() function. Add the following lines before 'return answered_correctly'. self.activity_count += 1 if answered_correctly: self.correct_answer_count += 1 CUSTOMIZE THE FUNCTION FOR MATH PROBLEMS: In order to customize this function for math problems, you can change it to take two numbers instead of the question. The only change is how you draw the problem. The following example is for addition problems. To call this function, you would use something like self.ask_addition_question(1,4,5) def ask_addition_question(self,number1,number2,correct_answer): answered_correctly = False activity_completed = False user_answer = "" while not activity_completed: for event in pygame.event.get(): if event.type == pygame.QUIT: sys.exit() elif event.type == pygame.KEYDOWN: if event.key == K_RETURN: activity_completed = True answered_correctly = (string.lower(user_answer) == string.lower(str(correct_answer))) elif event.key == K_BACKSPACE: user_answer = user_answer[0:-1] elif event.key in range(256): user_answer += chr(event.key) # Draw everything to the screen self.screen.blit(self.background, (0, 0)) # Draw the problem font = pygame.font.Font(None, 30) text = font.render(str(number1), 1, (0,0,0)) textrect = text.get_rect() textrect.top = 325 textrect.right = 200 self.screen.blit(text, textrect) text = font.render(str(number2), 1, (0,0,0)) textrect = text.get_rect() textrect.top = 350 textrect.right = 200 self.screen.blit(text, textrect) text = font.render("+", 1, (0,0,0)) textrect = text.get_rect() textrect.top = 350 textrect.left = 150 self.screen.blit(text, textrect) text = font.render("_____", 1, (0,0,0)) textrect = text.get_rect() textrect.top = 360 textrect.right = 200 self.screen.blit(text, textrect) # Give instructions for submitting the answer font = pygame.font.Font(None, 30) text = font.render("Press Enter to submit your answer.", 1, (0,0,0)) textrect = text.get_rect() textrect.centerx = self.area.centerx textrect.bottom = self.area.bottom - 100 self.screen.blit(text, textrect) # Draw the user's input font = pygame.font.Font(None, 30) text = font.render(user_answer, 1, (0,0,0)) textrect = text.get_rect() textrect.top = 390 textrect.right = 200 self.screen.blit(text, textrect) pygame.display.flip() return answered_correctly