I'm using the random module in order to display 25 different words. These words are going to be displayed in a 5 by 5 grid. Using a text file which contains 26 words, I want 25 words to be printed in this grid. However, the words printed cannot be repeated and they have to be picked at random. Then how would I be able to get the spare word from that list to use later in the code?
with open("file.txt") as x:
25words= x.read().splitlines()
def 5_by_5(l):
grid = [listofwords[i:i+5] for i in range(0, len(listofwords), 5)]
for l in grid:
print("".join("{:10}".format(i) for i in l))
listofwords= [random.choice(25words) for x in range(25)]
So at the moment the code can display the 5 by 5 grid but the words are repeated. How do I get it so that every word in the grid is different and then the 26th word that has not been used is identified as something which can be referred to later on?
Aucun commentaire:
Enregistrer un commentaire