import randomfor _ in range(10):#进行比赛的次数 my_list =['剪刀','石头','布'] player = input("请输入序号1剪刀、2石头、3布") if player: player =int(player) s =[i for i in range(1,4)] if player not in s: print("请输入正确的号码") continue index = random.randint(1, 3) #给电脑绑定序号 cumputer =my_list[index -1] print(cumputer) #思路:先考虑你赢得各种情况 if player==1 and index ==3 or player == 2 and index ==1 or player==3 and index==2 : print("好厉害你赢了,电脑出了%s" % cumputer) elif player ==index: print("平局电脑出了%s" % cumputer) else: print("你输了电脑出了%s" % cumputer)
来源:https://www.cnblogs.com/niucunguo/p/11938269.html