# 电脑出拳 random工包产生一个随机数
import random
# 战果统计
win = 0
lose = 0
draw = 0
xia = 0
allwe = input('你要出什么?石头1,布2,剪刀3)') # 字符串 str ‘123’ “1123”
for we in allwe:
computer=random.randint(1,3) # 数字 int 123
# 我们出拳 input
try:
we = int(we) # 将字符串转成数字
# 3.比较判断
result = computer-we
# 如果 we的值在1-3之间
if we>=1 and we<=3:
# 判断输赢
if result==-1 or result==2:
print('我们赢了')
win = win +1
elif result==1 or result==-2:
print('我们输了')
lose = lose+1
else :
print('平局')
draw = draw +1
# 否则,打印请不要瞎出
else:
print('请不要瞎出')
xia = xia +1
# 如果电脑出了1,我们就打印电脑出了石头
if computer == 1:
print('电脑出了石头')
elif computer ==2:
print("电脑出了布")
elif computer == 3:
print("电脑出了剪刀")
if we == 1:
print('我们出了石头')
elif we ==2:
print("我们出了布")
elif we == 3:
print("我们出了剪刀")
except:
print("请不要blind out")
xia = xia + 1
print("我们赢了%d局"%win)
print("我们输了%d局"%lose)
print("我们平局了%d局"%draw)
print("我们瞎出了%d局"%xia)
tina -升级了猜拳游戏
最新推荐文章于 2024-05-15 22:09:59 发布