首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >Python机器人游戏

Python机器人游戏
EN

Stack Overflow用户
提问于 2018-09-26 07:36:37
回答 1查看 121关注 0票数 0

当我使用!luck xx时,下面的代码运行得很好,当数量很低时,它会显示数量很低,但当我使用!luck -xx时,它仍然会不断添加数量。

那么如何禁用使用-xx数量呢

代码语言:javascript
复制
@bot.command(pass_context=True)
async def luck(ctx, amounty: int):
    primary_id = ctx.message.author.id
    if primary_id not in amounts:
        await bot.say("not registered")
    elif amounts[primary_id] < amounty:
        await bot.say("low balance")
    else:
        amounts[primary_id] -= amounty
        a = random.randint(1,2)
        if a == 1:
            amounts[primary_id] += amounty * 2
            await bot.say("You Won")
        else:
            await bot.say("You lost")
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-09-26 07:45:24

只需检查数字是否为负数,如果是,则返回一个空

代码语言:javascript
复制
  if amounty<0:
    await bot.say("Can't use a negative number")
    return
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52507952

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档