print("游戲介紹:\n"
? ? ? "數(shù)字1代表石頭\n"
? ? ? "數(shù)字2代表剪刀\n"
? ? ? "數(shù)字3代表布")
# 游戲次數(shù)
playnumber=0
# 玩家勝利次數(shù)
play_winner=0
# 電腦勝利次數(shù)
computer_winner=0
# 平局?jǐn)?shù)
draw=0
while True:
# 判斷輸入的手勢是否合理
? ? while True:
guess=int(input("請輸入你的手勢:"))
if guess!=1 and guess!=2 and guess!=3:
print("輸入有誤翘簇,請重新輸入妹沙!")
else:
break
? ? if guess==1:
print("玩家出【石頭】")
elif guess==2:
print("玩家出【剪刀】")
elif guess==3:
print("玩家出【布】")
import random
computer=random.randint(1,3)
if computer==1:
print("電腦出【石頭】")
elif computer==2:
print("電腦出【剪刀】")
elif computer==3:
print("電腦出【布】")
if guess==1 and computer==2 or guess==2 and computer==3 or guess==3 and computer==1:
play_winner +=1
? ? ? ? playnumber+=1
? ? ? ? print("玩家勝利揩魂!勝利次數(shù)為%s次"%play_winner)
elif guess==1 and computer==3 or guess==2 and computer==1 or guess==3 and computer==1:
computer_winner +=1
? ? ? ? playnumber+=1
? ? ? ? print("電腦勝利!勝利次數(shù)為:%s次"%computer_winner)
elif guess==computer:
draw+=1
? ? ? ? playnumber+=1
? ? ? ? print("平局拐揭!平局?jǐn)?shù)為{}".format(draw))
# 電腦和玩家進(jìn)行猜拳撤蟆,最先勝利4局的勝利
? ? if play_winner==4 or computer_winner==4:
break
# 10局之后,顯示玩家勝利局?jǐn)?shù)堂污、電腦勝利局?jǐn)?shù)和平局
if playnumber==10:
print("玩家勝利局?jǐn)?shù)為{}局家肯,電腦勝利局?jǐn)?shù)為{}局,平局?jǐn)?shù)為{}局".format(play_winner,computer_winner,draw))
print("游戲結(jié)束")