PromptBase
Close icon
General
Home
Marketplace
Hire
Create
Login
Sell
Explore
🤖 GPT

Generate Python Code For A Board Game

Generate Python Code For A Board Game gpt prompt mini thumbnail
1Heart icon
Favorites
104Eye icon
Views
GPT-3.5-TURBO
TestedTick icon
TipsTick icon
This prompt instructs you to create a Python program that simulates a tic-tac-toe game. The program allows two players to play. It displays the current state of the game board after each turn, and either determines the winner or declares a draw when the game is finished.
...more
$2.99
Get prompt
After purchasing, you will gain access to the prompt file which you can use with GPT or the app builder. You'll receive 20 free generation credits with this purchase. By purchasing this prompt, you agree to our terms of service.
Over 1 month ago

Prompt Details

Model
Chat - GPT-3.5 (gpt-3.5-turbo)
Token size
68 ($0.00010 / call)
Example input
[Name of Game eg. tic-tac-toe]:tic-tac-toe,[# of players eg. 2]:2
Example output
def print_board(board): for row in board: print(" | ".join(row)) print("-" * 9) def check_winner(board, player): for row in board: if all(cell == player for cell in row): return True for col in range(3): if all(board[row][col] == player for row in range(3)): return True if all(board[i][i] == player for i in range(3)) or all(board[i][2 - i] == player for i in range(3)): return True return False def is_draw(board): for row in board: if " " in row: return False return True def play_game(): board = [[" " for _ in range(3)] for _ in range(3)] current_player = "X" winner = None print("Welcome to Tic-Tac-Toe!") print_board(board) while True: try: row = int(input(f"Player {current_player}, enter the row (0, 1, or 2): ")) col = int(input(f"Player {current_player}, enter the column (0, 1, or 2): ")) if board[row][col] != " ": print("That position is already taken. Try again.") continue board[row][col] = current_player except (ValueError, IndexError): print("Invalid input. Please enter valid row and column values.") continue print_board(board) if check_winner(board, current_player): winner = current_player break if is_draw(board): break current_player = "O" if current_player == "X" else "X" if winner: print(f"Player {winner} wins! Congratulations!") else: print("It's a draw! Good game!") if __name__ == "__main__": play_game()
Browse Marketplace