Last active
September 12, 2023 02:29
-
-
Save yuyueugene84/d92062168bd83edc1c9dbb1acd3b52bf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
print("-------歡迎來到剪刀石頭布!-------") | |
name = input("請輸入您的名稱:") | |
# 玩家出拳 | |
user_hand = int(input("請出拳 (1) 剪刀 (2) 石頭 (3) 布:")) | |
# 電腦出拳 | |
comp_hand = random.randint(1,3) | |
# 判斷玩家是贏還是輸 | |
if user_hand == comp_hand: | |
print("平手!") | |
elif user_hand == 1 and comp_hand == 3: | |
print("你贏了!") | |
elif user_hand == 2 and comp_hand == 1: | |
print("你贏了!") | |
elif user_hand == 3 and comp_hand == 2: | |
print("你贏了!") | |
else: | |
print("你輸了!") | |
# 將玩家的數字轉換成文字 | |
if user_hand == 1: | |
user_hand = "剪刀" | |
elif user_hand == 2: | |
user_hand = "石頭" | |
elif user_hand == 3: | |
user_hand = "布" | |
# 將電腦的數字轉換成文字 | |
if comp_hand == 1: | |
comp_hand = "剪刀" | |
elif comp_hand == 2: | |
comp_hand = "石頭" | |
elif comp_hand == 3: | |
comp_hand = "布" | |
# 輸出結果 | |
print("==================================================================") | |
print(name + " 出了: " + user_hand + ", 電腦出了: " + comp_hand) | |
print("==================================================================") | |
print("感謝你玩剪刀石頭布!") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment