Search code examples
python-3.xinputsplitconcatenationtic-tac-toe

How do I concatenate strings from input()?


I'm trying to create a game of naughts and crosses. In order to prevent the same move being made more than once, I have made a move_log variable, move_log = [], which logs all moves and an error message which makes the player aware that they need to select a new move to proceed, this is to happen if their initial move is in the move_log. After each move, I have written the following to update the move_log:

move_log = []

.........

move_log += player_move

and

move_log = []

.........

move_log += pc_move

The available moves are 'tl', 'tm', 'tr', 'ml', 'm', 'mr', 'bl', 'bm'or'br'

My problem is that, once in the list of the move_log variable, this is the list:

['b', 'r'] # example of list after 1st move

This will make my if statement somewhat tricky, any suggestions? Many thanks!


Solution

  • Try using append instead of the += operator. They have different behaviour as described in the answer for this question

    move_log.append(pc_move)
    

    Here's an example: https://repl.it/repls/ImpassionedSwiftTrust