so I have been making a memory game in which a 3x3 grid is displayed, and is removed after 30 seconds. After, another 3x3 grid is displayed but one of the words from the first grid has been replaced with another word. The user has to guess the original word that has been replaced. However I am unsure how to code this. here is my code:
import random # imports the random module, to generate the words
import time # imports the time module, used for the countdown
try:
with open ('patrick star.txt') as f: # opens the text file
words = random.sample([x.rstrip() for x in f], 9)
grid = [words[i:i + 3] for i in range(0, len(words), 3)] # puts the words into a 3x3 grid
for x,y,z in grid:
print (x,y,z) # prints the 3x3 grid
except IOError:
print("The code does not seem to be working")
time.sleep(30) # displays it for 30 seconds
import os
os.system('cls') # this function clears the screen after countdown
print("Time's up!")
try:
with open ('patrick star.txt') as f: # opens the text file
words = random.sample([x.rstrip() for x in f], 9)
grid = [words[i:i + 3] for i in range(0, len(words), 3)] # puts the words into a 3x3 grid
for x,y,z in grid:
print (x,y,z) # prints the 3x3 grid