Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3
- #
- # https://www.reddit.com/r/learnpython/comments/4vzqr6/strange_indentation_error_when_trying_to_run_tic/
- #
- # --- constants --- UPPER_CASE
- PLAYER_1 = 'x'
- PLAYER_2 = 'o'
- # --- class --- CamelCase
- # empty
- # --- functions --- lower_case
- def move(player, game):
- coords = input("Give me coordinates of the move that you want to make!\nRow then colomn, in format row,col (e.g. 1,1 up to 3,3): ")
- row, col = coords.split(",")
- row = int(row.strip()) - 1
- col = int(col.strip()) - 1
- game[row][col] = player
- def display(board):
- for row in board:
- print(' '.join(row))
- # --- main ---
- if __name__ == "__main__":
- print("Welcome to Tic Tac Toe!")
- print()
- print("The game is exactly how you think it works.")
- print()
- while True:
- choice = input("Wanna play? If no then type `n`").lower()
- if choice == 'n':
- break
- # gameboard
- gameboard = [
- ['.', '.', '.'],
- ['.', '.', '.'],
- ['.', '.', '.']
- ]
- # keeps track of how many moves had been made
- count = 0
- while count < 10:
- move(PLAYER_1, gameboard)
- display(gameboard)
- count += 1
- move(PLAYER_2, gameboard)
- display(gameboard)
- count += 1
- print("End of this game")
Add Comment
Please, Sign In to add comment