python猜拳小游戏

余生长醉 提交于 2019-12-05 17:48:30
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)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!