jeudi 24 septembre 2015

How to randomize the position of a variable in a grid (in python)

I have been making a game in python where a 2x2 grid containing four letters is displayed. One of the letters is replaced with a new letter. Each time the grid is displayed, the new letter must be a different letter and it must have a different position on the grid. I have created a variabe called 'newletter', but i am having trouble randomizing the position of this variable on the grid each time it is displayed. My code so far works, but it does not change the position of the variable.

'letters' is a textfile which contains 5 different letters

random.shuffle (letters)

print (letters[0]+ " " +letters[1])
print (letters[2]+ " " +letters[3])

random.shuffle (letters)

replacedletter = letters[3]
newletter = letters[4]

print (letters[0]+ " " +letters[1])
print (letters[2]+ " " +newletter)

Any help would be appreciated




Aucun commentaire:

Enregistrer un commentaire