a = input("请输入:剪刀(0)、石头(1)、布(2):")
b = int(a)
if b == 0:
user = "剪刀"
print("你出的是%s" % user)
elif b == 1:
user = "石头"
print("你出的是%s" % user)
elif b == 2:
user = "布"
print("你出的是%s" %user)
while b != 0 and b != 1 and b != 2:
print("请重新输入正确的数字!")
b = int(input("请输入:剪刀(0)、石头(1)、布(2):"))
if b == 0:
user = "剪刀"
elif b == 1:
user = "石头"
elif b == 2:
user = "布"
else:
continue
print("你出的是%s" %user)
else:
c = random.randint(0, 2)
if c == 0:
computer = "剪刀"
elif c == 1:
computer = "石头"
else:
computer = "布"
print("电脑出的是%s" %computer)
if b == c:
print("平局!")
elif b == 0 and c == 2 or b == 1 and c ==0 or b ==2 and c == 1:
print("你赢了!")
else:
print("你输了!")
运行结果如下: