·猜拳游戏(升级版)
import random
cnt=input(\"请输入要进行的游戏次数:\")
print(\"\\n\")
cnt=int(cnt)
while cnt:
player_input = input(\"请输入(0剪刀、1石头、2布):\")
player = int(player_input)
if player<0 or player>2:
print(\"请按照游戏规则输入数字哦---\\n\")
continue
computer = random.randint(0,2)
if (computer - player == 2) or (computer - player == 1)or (computer - player == -1):
print(\"电脑出的是%s,恭喜,你赢了!\\n\"%computer)
elif computer - player == 0:
print(\"电脑出的是%s,平局!\\n\"%computer)
else:
print(\"电脑出的是%s,你输了!\\n\"%computer)
cnt-=1
print(\"------游戏结束------\\n\")
来源:https://www.cnblogs.com/zhang-a-d/p/14822984.html
图文来源于网络,如有侵权请联系删除。