代码拉取完成,页面将自动刷新
# 剪刀石头布 作业
import random
import msvcrt
selections=["剪刀","石头","布"]
cnt=0
win=0
while cnt<5:
# robot=random.choice(selections)
robot=random.randint(0,2)
player=input("请出拳:")
if player in selections:
ip=selections.index(player)
if ip==robot:
print("平局!")
# elif player=="剪刀" and robot=="石头":
# print("你输了!")
# cnt+=1
# elif player=="剪刀"and robot=="布":
# print("你赢了!")
# cnt+=1
# win+=1
# elif player=="石头"and robot=="剪刀":
# print("你赢了!")
# cnt+=1
# win+=1
# elif player=="石头"and robot=="布":
# print("你输了!")
# cnt+=1
# elif player=="布"and robot=="剪刀":
# print("你输了!")
# cnt+=1
# elif player=="布"and robot=="石头":
# print("你赢了!")
# cnt+=1
# win+=1
elif ip-robot==1 or robot-ip==2:
print("你赢了!")
cnt+=1
win+=1
else:
print("你输了!")
cnt+=1
else:
print("请按规则输入!")
if win>=3:
print("你赢了",win,"局")
else:
print("你输了!!!")
print("——————————按任意键退出……——————————")
msvcrt.getch()
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。