<jupyter_start><jupyter_text>Tic-Tac-Toe in Python<jupyter_code>#We have a Dictionary as our board where each number is a key represented by a value.
theBoard = {'7': ' ' , '8': ' ' , '9': ' ' ,
            '4': ' ' , '5': ' ' , '6': ' ' ,
            '1': ' ' , '2': ' ' , '3': ' ' }
#am empty list to store keys is made, and incoming key values are appended to the board 
board_keys = []

for key in theBoard:
    board_keys.append(key)
#printBoard function is created to print the board on the scrren after every move of the player
def printBoard(board):
    print(board['7'] + '|' + board['8'] + '|' + board['9'])
    print('-+-+-')
    print(board['4'] + '|' + board['5'] + '|' + board['6'])
    print('-+-+-')
    print(board['1'] + '|' + board['2'] + '|' + board['3'])
#this is the main function of our game and super easy to follow 
def game():

    turn = 'X' # set a turn to X initially
    count = 0  # counter variable


    for i in range(10):   # loops from 1 to 9th position
        printBoard(theBoard)   #print board
        print("It's your turn," + turn + ".Move to which place?")    

        move = input()  #user input to enter its position on the board
        if theBoard[move] == ' ': # checks if input place is empty on the board 
          theBoard[move] = turn  # if empty replaces by the turn either X or O
          count += 1    # increases the counter
        else:
            print("That place is already filled.\nMove to which place?")   #if place is filled gives a messege
            continue

        # Now we will check if player X or O has won,for every move after 5 moves. why 5 becuase one player will get 3 moves by this time and can possibliy win 
        if count >= 5:
          #checking all possible conditions of match / win on a tic tac toe
            if theBoard['7'] == theBoard['8'] == theBoard['9'] != ' ': # across the top 
                printBoard(theBoard)   #if conditon satisfies 
                print("\nGame Over.\n")                
                print(" **** " +turn + " won. ****")        #win msg        
                break       #break loop
            elif theBoard['4'] == theBoard['5'] == theBoard['6'] != ' ': # across the middle
                printBoard(theBoard)
                print("\nGame Over.\n")                
                print(" **** " +turn + " won. ****")
                break
            elif theBoard['1'] == theBoard['2'] == theBoard['3'] != ' ': # across the bottom
                printBoard(theBoard)
                print("\nGame Over.\n")                
                print(" **** " +turn + " won. ****")
                break
            elif theBoard['1'] == theBoard['4'] == theBoard['7'] != ' ': # down the left side
                printBoard(theBoard)
                print("\nGame Over.\n")                
                print(" **** " +turn + " won. ****")
                break
            elif theBoard['2'] == theBoard['5'] == theBoard['8'] != ' ': # down the middle
                printBoard(theBoard)
                print("\nGame Over.\n")                
                print(" **** " +turn + " won. ****")
                break
            elif theBoard['3'] == theBoard['6'] == theBoard['9'] != ' ': # down the right side
                printBoard(theBoard)
                print("\nGame Over.\n")                
                print(" **** " +turn + " won. ****")
                break 
            elif theBoard['7'] == theBoard['5'] == theBoard['3'] != ' ': # diagonal
                printBoard(theBoard)
                print("\nGame Over.\n")                
                print(" **** " +turn + " won. ****")
                break
            elif theBoard['1'] == theBoard['5'] == theBoard['9'] != ' ': # diagonal
                printBoard(theBoard)
                print("\nGame Over.\n")                
                print(" **** " +turn + " won. ****")
                break 

        # If neither X nor O wins and the board is full, we'll declare the result as 'tie'.
        if count == 9:
            print("\nGame Over.\n")                
            print("It's a Tie!!")

        # Now we have to change the player after every move.
        if turn =='X':
            turn = 'O'
        else:
            turn = 'X'        
    
    # Now we will ask if player wants to restart the game or not.
    restart = input("Do want to play Again?(y/n)")
    if restart == "y" or restart == "Y":  
        for key in board_keys:
            theBoard[key] = " "

        game()

if __name__ == "__main__":
    game()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.15168661588683352, 'fraction_numerical': 0.011534276387377584, 'mean_word_length': 1.587837837837838, 'pattern_counts': {'":': 2, '<': 5, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '298046', 'license': 'MIT', 'n_tokens_mistral': 1347, 'n_tokens_neox': 1259, 'n_words': 428, 'path': 'assignment2/Tic_Tac_Toe.ipynb', 'repo_name': 'bhanvimenghani/PythonSeries1.0', 'size': '4595'}