print(“游戏介绍:\n”
"数字1代表石头\n"
"数字2代表剪刀\n"
"数字3代表布")
游戏次数
playnumber=0
玩家胜利次数
play_winner=0
电脑胜利次数
computer_winner=0
平局数
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("玩家胜利!胜利次数为%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("电脑胜利!胜利次数为:%s次"%computer_winner)
elif guess==computer:
draw+=1
playnumber+=1
print("平局!平局数为{}".format(draw))
电脑和玩家进行猜拳,最先胜利4局的胜利
if play_winner==4 or computer_winner==4:
break
10局之后,显示玩家胜利局数、电脑胜利局数和平局
if playnumber==10:
print(“玩家胜利局数为{}局,电脑胜利局数为{}局,平局数为{}局”.format(play_winner,computer_winner,draw))
print(“游戏结束”)