總網頁瀏覽量

【 Python學習 】剪刀石頭布程式 玩家與電腦

import random

player = None
computer = None
running = True
options = ("剪刀", "石頭", "")

while running:
while True:
player = input("請輸入剪刀、石頭、布:")
if player not in options:
print("input error, try again")
else:
break
# 電腦隨機選擇
computer = random.choice(options)
print(f"player:{player}, computer:{computer}")

# 判斷輸贏
if player == computer:
print("平手")
elif player == "剪刀" and computer == "":
print("玩家勝利")
elif player == "石頭" and computer == "剪刀":
print("玩家勝利")
elif player == "" and computer == "石頭":
print("玩家勝利")
else:
print("電腦勝利")
player_again = input("再玩一局?(y/n)").lower()
if not player_again == "y":
running = False

print("謝謝遊玩")

沒有留言:

張貼留言

鮮乳坊鮮乳・優格全系列推薦|頂級乳源,每天喝得到的安心濃郁

在每天都離不開牛奶與優格的生活裡,「 這杯鮮乳從哪裡來?安不安全?好不好吸收? 」其實比價格更重要。 這也是為什麼近年越來越多人指名選擇 鮮乳坊鮮乳與鮮乳製品 ——不只是好喝,而是 真正把關乳源、從牧場開始負責 。 本篇一次整理鮮乳坊三大熱賣系列: 👉 豐樂鮮乳、A2β酪蛋白鮮...