美文网首页
python写的猜拳小游戏

python写的猜拳小游戏

作者: 炫彩流萤ying | 来源:发表于2019-06-03 13:57 被阅读0次

抄自:https://blog.csdn.net/qq_42712647/article/details/82354250

import random

while True:

    dian_nao = random.randint(1, 3) # 电脑出招

    play = int(input("请出招:1表示剪刀,2表示石头,3表示布,6表示退出游戏")) # 玩家出招

    if play == 1 and dian_nao == 3 or play == 2 and dian_nao == 1 or play == 3 and dian_nao == 2:

        print("电脑出"+ str(dian_nao)+"\n"+"恭喜你赢了!") # 以上情况出现一种表示玩家胜出

    elif play == dian_nao:

        print("电脑出"+ str(dian_nao)+"\n"+"平局!")

    elif play == 6:

        print("游戏以退出!")

        break

    else:

        print("电脑出"+ str(dian_nao)+"\n"+"很遗憾你输了!")

运行结果:

相关文章

网友评论

      本文标题:python写的猜拳小游戏

      本文链接:https://www.haomeiwen.com/subject/tedcxctx.html