python猜拳小游戏

import random

while True:
    game = {0:'剪刀', 1: '石头', 2: '布'}
    player = input('请输入:剪刀(0)  石头(1)  布(2)  退出(3):')

    # isdigit() 判断字符串是否为数字
    if player.isdigit():
        player = int(player)
        # 退出游戏
        if player == 3:
            print('退出成功,感谢你的使用!')
            break
        # 判断是否出指定数字
        if player not in game:
            print('请输入指定数字(0/1/2)!')
            continue
    else:
        print('请输入数字!')
        continue
       
    # 随机整数(0,1,2)
    computer = random.randint(0,2)

    print('player出: %s, computer出: %s' % (game[player], game[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('输了,不要走,洗洗手接着来,决战到天亮')

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值