猜拳判断:
用户可输入任意字符,当不是0,1,2时 程序会提示重新输入,直到输入内容是0,1,2为止。
import random
a = [0,1,2]
cpt = random.randint(0,2)
while True:
your = input("请输入:剪刀(0)、石头(1)、布(2): ")
if your in str(a):
print("你输入的数为: ", your)
print("随机数为: ", cpt)
if int(your) == 0 and cpt == 1:
print("你输了!!!")
elif int(your) == 1 and cpt == 2:
print("你输了!!!")
elif int(your) == 2 and cpt == 0:
print("你输了!!!")
elif int(your) == cpt:
print("平局, once again")
else:
print("你赢了 ~~!!!!")
break
else:
print("请重新输入")