{}
run-icon
main.py
import random def play_game(): choices = ['剪刀', '石頭', '布'] print("歡迎來到剪刀石頭布遊戲!") player_choice = input("請輸入你的選擇(剪刀、石頭、布):") if player_choice not in choices: print("輸入錯誤,請選擇 剪刀、石頭 或 布") return computer_choice = random.choice(choices) print(f"電腦出拳:{computer_choice}") if player_choice == computer_choice: print("平手!") elif (player_choice == '剪刀' and computer_choice == '布') or \ (player_choice == '石頭' and computer_choice == '剪刀') or \ (player_choice == '布' and computer_choice == '石頭'): print("你贏了!🎉") else: print("你輸了!😢") # 執行遊戲 play_game()
Output