Python 我如何让我的机器人知道给出的数字是高于还是低于答案?[discord.py]

Python 我如何让我的机器人知道给出的数字是高于还是低于答案?[discord.py],python,discord,bots,discord.py,Python,Discord,Bots,Discord.py,我在做一个数字猜谜游戏,我想知道如何让它告诉你你的答案是高于还是低于答案?以下是我目前的代码: async def number(ctx): await ctx.send('I\'m thinking of a number from one to ten. Try to guess which number!') number = random.randint(1, 10) answer = await client.wait_for('message', check=

我在做一个数字猜谜游戏,我想知道如何让它告诉你你的答案是高于还是低于答案?以下是我目前的代码:

async def number(ctx):
    await ctx.send('I\'m thinking of a number from one to ten. Try to guess which number!')
    number = random.randint(1, 10)
    answer = await client.wait_for('message', check=lambda message: message.author == ctx.author and message != "")
    answer = answer.content

    loop_counter = 0
    while answer.lower() != number:
        loop_counter += 1
        if loop_counter >= 2:
            await ctx.send(f'sorry dude, the correct number was {number}')
            break
        await ctx.send('Incorrect, try again')
        answer = await client.wait_for('message', check=lambda message: message.author == ctx.author and message != "")
        answer = answer.content

        if answer.lower() == number:
            "[testing]" ```
Thanks!

while
循环中,还可以添加
if-else
循环

while answer.lower() != number:
    if answer.lower()<number:
        #Do things if the number is lower
    else: 
        #Do things if the number is higher
    loop_counter += 1
    if loop_counter >= 2:
        await ctx.send(f'sorry dude, the correct number was {number}')
        break
while answer.lower()!=编号:
如果answer.lower()=2:
等待ctx.send(对不起,伙计,正确的号码是{number})
打破

注意:虽然通常在检查某个数字是否较高/较低时,不能使用
else
,因为这些数字可能相等,如果它们相等,循环就不会启动,但您可以首先在此处使用
else
,,如果答案为0.lower()==number:因为
answer
str
对象,而
number
整数。所以你不能比较它们。而且你也不必等待两次。也可以将其添加到while循环中。您可以使用以下选项:

@client.command()
异步def编号(ctx):
等待ctx.send('我在想一个从1到10的数字。试着猜哪个数字!')
number=random.randint(1,10)
循环计数器=0
当循环计数器<2时:
anwser=client.wait_for('message',check=lambda message:message.author==ctx.author)
尝试:
answ=int(answer.content)#这里它将尝试将答案返回到整数。
除值错误外:
等待ctx.send('请键入数字')#如果它不是整数,则它将通过并发送警告。
通过
如果answ==编号:
等待ctx.send(“您找到了号码”)#如果用户找到答案,它将发送消息并结束循环。
返回
其他:

等待ctx.send('抱歉,回答错误。答案更高。'))如果代码中的数字answAny
#
表示忽略此行。把
#
换成你喜欢的任何代码。对不起,我打错了一个字母。将
anwser=client.wait_for
更改为
answer=client.wait_for
。这将删除所有错误。。但是现在,在我尝试输入一个数字后,什么也没有发生。我找不到解决方案。。