import random
#1代表true
while 1:
#生成随机数
s = int(random.randint(1, 3))
#赋值给生成的随机数
if s == 1:
ind = "剪刀"
if s == 2:
ind = "石头"
if s == 3:
ind = "布"
m = input("规则:输入剪刀、石头、布开始游戏,输入end结束游戏")
blist = ['剪刀', '石头', '布']
#判断当输入值m不是blist的值和end时提示有误
if (m not in blist) and (m != 'end'):
print('\033[1;30;41m' + '输入有误请看规则!' + '\033[0m')
#当blist
elif (m not in blist) and (m == 'end'):
while 1:
x = input("输入yes退出,输入no继续")
if (x != 'yes') and (x != 'no'):
print("输入有误,请重新输入!")
elif (x == 'yes'):
print('退出游戏')
exit()
elif (x == 'no'):
print('返回游戏')
break
#当输入的值m==赋值生成的随机数时
elif m == ind:
print("电脑出了:" + ind + ",平局!")
# 当输入的值m打赢赋值生成的随机数时
elif (m == '石头' and ind == '剪刀') or (m == '剪刀' and ind == '布') or (m == "布" and ind == "石头"):
print("电脑出了:" + ind + ",你赢了")
# 当输入的值m输赋值生成的随机数时
elif (m == '石头' and ind == '布') or (m == '剪刀' and ind == '石头') or (m == "布" and ind == "剪刀"):
附图