(2018-03-28.Python从Zero到One)三、Python基础__3.2.4应用:猜拳游戏

上一篇文章为:→3.2.3if嵌套

应用:猜拳游戏

<1>运行效果:

(2018-03-28.Python从Zero到One)三、Python基础__3.2.4应用:猜拳游戏_第1张图片
day04_python基础-01.gif

<2>参考代码:


    import random

    player = input('请输入:剪刀(0)  石头(1)  布(2):')

    player = int(player)

    computer = random.randint(0,2)

    # 用来进行测试
    #print('player=%d,computer=%d',(player,computer))

    if ((player == 0) and (computer == 2)) or ((player ==1) and (computer == 0)) or ((player == 2) and (computer == 1)):
        print('获胜,哈哈,你太厉害了')
    elif player == computer:
        print('平局,要不再来一局')
    else:
        print('输了,不要走,洗洗手接着来,决战到天亮')

下一篇文章为:→3.2.5循环语句介绍

你可能感兴趣的:((2018-03-28.Python从Zero到One)三、Python基础__3.2.4应用:猜拳游戏)