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("謝謝遊玩")
沒有留言:
張貼留言