gpt-3.5-turbo-0613· OpenAI WildChat-4.8M (AI2)
write me a rock paper scissors game in python with (1start, 2result, 3_ all results,…
- User
write me a rock paper scissors game in python with (1_start, 2_result, 3_ all results, 4_exit) buttons
- Assistant
Sure! Here's a simple implementation of a Rock Paper Scissors game in Python using tkinter for the GUI:
import tkinter as tk from tkinter import messagebox import random # Function to determine the winner def play(player_choice): choices = {'rock': 0, 'paper': 1, 'scissors': 2} computer_choice = random.choice(['rock', 'paper', 'scissors']) if player_choice == computer_choice: result = "It's a tie!" elif (choices[player_choice] - choices[computer_choice]) % 3 == 1: result = "You win!" else: result = "Computer wins!" messagebox.showinfo("Result", result) # Adding the result to the list results.append((player_choice, computer_choice, result)) # Function to display all results def display_results(): result_text = "" for result in results: result_text += f"Player: {result[0]}, Computer: {result[1]}, Result: {result[2]}\n" messagebox.showinfo("All Results", result_text) # Function to exit the game def exit_game(): window.destroy() # Main window setup window = tk.Tk() window.title("Rock Paper Scissors") # Buttons setup btn_start = tk.Button(window, text="1_start", width=10, command=lambda: play("rock")) btn_start.pack(pady=10) btn_result = tk.Button(window, text="2_result", width=10, command=display_results) btn_result.pack(pady=5) btn_all_results = tk.Button(window, text="3_ all results", width=10, command=display_results) btn_all_results.pack(pady=5) btn_exit = tk.Button(window, text="4_exit", width=10, command=exit_game) btn_exit.pack(pady=10) # List to store all results results = [] window.mainloop()You can copy this code and run it in Python to play the game. When you click on the "1_start" button, the game will randomly choose its move and display the result in a message box. Clicking on the "2_result" button will show the result of the last game played, and clicking on the "3_ all results" button will show all the results played so far. Finally, clicking on the "4_exit" button will close the game window.