The code -- {Open it in Python Editor and run it} from random import randint def display(board): print(board[7] + '|' + board[8] + '|' + board[9]) print(board[4] + '|' + board[5] + '|' + board[6]) print(board[1] + '|' + board[2] + '|' + board[3]) def player_chooses_marker(player): while True: PM = input(f'Player {player}; Enter your marker: ') if PM in ['X','O']: print('Okay.') break else: print('IT WAS AN INVALID RESPONSE!') input('Press Enter to continue: ') print('\n' * 100) if PM == 'X': return 'X','O' else: return 'O','X' def is_ready(): while True: ready = input('Are you ready? Type Yes or No: ') if ready.lower()[0] in ['y','n']: print('Okay.') return ready.lower()[0] == 'y' else: print('IT IS AN INVALID RESPONSE!') input('Press Enter to continue: ') print('\n' * 100) def space_left(board,loc): return board[loc] == ' ' def any_space_in_full_board(board): for i in board: if i == ' ': return True else: pass return False def win_check(board,mark): return ((board[7] == mark and board[8] == mark and board[9] == mark) or # across the top (board[4] == mark and board[5] == mark and board[6] == mark) or # across the middle (board[1] == mark and board[2] == mark and board[3] == mark) or # across the bottom (board[7] == mark and board[4] == mark and board[1] == mark) or # down the middle (board[8] == mark and board[5] == mark and board[2] == mark) or # down the middle (board[9] == mark and board[6] == mark and board[3] == mark) or # down the right side (board[7] == mark and board[5] == mark and board[3] == mark) or # diagonal (board[9] == mark and board[5] == mark and board[1] == mark)) # diagonal def replay(): while True: ask_func = input('Do you want to play again? Type Yes or No: ') if ask_func.lower()[0] in ['y','n']: print('Okay. ') return ask_func.lower()[0] == 'y' else: print('INVALID RESPONSE!') input('Press Enter to continue: ') print('\n' * 100) def first_player(): i = randint(0,1) if i == 0: return 'Player 1' else: return 'Player 2' def player_gameplay(player): while True: x = input(f'Player {player}; Choose your location (1 - 9): ') if x.isdigit() and int(x) in range(1,10): print('OKAY.') return int(x) else: print('INVALID RESPONSE!') input('Press Enter to continue: ') print('\n' * 100) print('Welcome to Tic - Tac - Toe!') while True: theBoard = [' '] * 10 marker1,marker2 = player_chooses_marker(1) turn = first_player() print(turn + ' will go first.') if is_ready(): game_on = True else: game_on = False while game_on: if turn == 'Player 1': print('\n' * 100) display(theBoard) position = player_gameplay(1) theBoard[position] = marker1 if win_check(theBoard,marker1): print('\n' * 100) display(theBoard) print('Yay! Player 1 won!') game_on = False else: if not any_space_in_full_board(theBoard): print('\n' * 100) display(theBoard) print('The game is a TIE!') game_on = False else: turn = 'Player 2' else: print('\n' * 100) display(theBoard) position = player_gameplay(2) theBoard[position] = marker2 if win_check(theBoard, marker2): print('\n' * 100) display(theBoard) print('Yay! Player 2 won!') game_on = False else: if not any_space_in_full_board(theBoard): print('\n' * 100) display(theBoard) print('The game is a TIE!') game_on = False else: turn = 'Player 1' rep = replay() if not rep: break
PLEASE CHECK IT OUT AND PLS GIMME MORE PROJECT IDEAS