Python例子

Python例子-猜拳游戏

Python例子-猜拳游戏:跟电脑玩石头,剪刀,布游戏。

    赢了就提示:赢了,你好厉害哦,下一把我一定要赢你。

    输了就提示:输了,不要走,洗洗手接着来,决战到天亮。

    平局就提示:势均力敌,继续干。。。

'''
Python例子-猜拳游戏:跟电脑玩石头,剪刀,布游戏。
赢了就提示:您赢了,你好厉害哦,下一把我一定要赢你。
输了就提示:您输了,不要走,洗洗手接着来,决战到天亮。
平局就提示:势均力敌,继续干。。。
'''
import random

while True:
    computer = random.randint(0,2)  #  返回 [0, 2] 之间的整数,包含 0 和 2
    player = int(input('请输入:剪刀(0)  石头(1)  布(2):'))
    if player not in [0, 1, 2]:
        print('输入有误,请重新输入')
    else:
        if ((computer == 0) and (player == 1)) or ((computer == 1) and (player == 2)) or ((computer == 2) and (player==0)):
            print('您赢了,你好厉害哦,下一把我一定要赢你。\n')
        elif computer == player:
            print('势均力敌,继续干。。。\n')
        else:
            print('您输了,不要走,洗洗手接着来,决战到天亮。\n')


最后修改:2020年2月24日 16:51