python写的猜拳小游戏

抄自: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写的猜拳小游戏_第1张图片

你可能感兴趣的:(python写的猜拳小游戏)