Aug-31-2020, 07:48 PM
I would probably just shuffle the list, then use the first one as my piece and the second as the opponent.
import random pieces = ["X", "O"] pieces = random.shuffle(pieces) # my piece is always pieces[0] and my opponent is pieces[1]If you really prefer to use separate variables for each piece (and I think there are reasons you shouldn't) then you could just sample the list like this...
import random pieces = ["X", "O"] piece, opponent = random.sample(pieces, k=2)