Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/363.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/github/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 我能’;t在使用aigram模块猜测数字的一侧编写算法_Python_Python 3.x_Telegram_Telegram Bot - Fatal编程技术网

Python 我能’;t在使用aigram模块猜测数字的一侧编写算法

Python 我能’;t在使用aigram模块猜测数字的一侧编写算法,python,python-3.x,telegram,telegram-bot,Python,Python 3.x,Telegram,Telegram Bot,我需要使用一个模块来编写一个电报机器人,该模块将猜测数字,但在编写机器人时,我遇到了一个问题。我无法解释我为Aigram模块编写的算法,或者更确切地说,我无法在“while”本身中进行第二次数字输入,因为在输入数字后,我会无休止地只输出一个“if”的结果。下面是我试图解释的算法 import random win = False randnum = random.randint(1,100) tr = 0 print(randnum) while win != True: try:

我需要使用一个模块来编写一个电报机器人,该模块将猜测数字,但在编写机器人时,我遇到了一个问题。我无法解释我为Aigram模块编写的算法,或者更确切地说,我无法在“while”本身中进行第二次数字输入,因为在输入数字后,我会无休止地只输出一个“if”的结果。下面是我试图解释的算法

import random
win = False
randnum = random.randint(1,100)
tr = 0
print(randnum)
while win != True:
    try:
        number = int(input())
        if number > 100 or number < 1:
            print('Please enter a number between 1 and 100')
            tr += 1
        elif  number < randnum:
            print('This number is less than the guessed, please try again.')
            tr += 1
        elif number > randnum:
            print('This number is greater than the guessed, please try again.')
            tr += 1
        elif number == randnum:
            print(f'Congratulations, you guessed right. You spent {tr} attempts on this')
            win = True
            tr = 0
    except:
        print('This is not a number. Try again')
        tr += 1

随机导入
赢=错
randnum=random.randint(1100)
tr=0
打印(随机数)
一边赢正确:
尝试:
number=int(输入())
如果数量大于100或数量小于1:
打印('请输入一个介于1和100'之间的数字)
tr+=1
elif编号<随机数:
打印('此数字小于猜测值,请重试')
tr+=1
elif编号>随机编号:
打印('此数字大于猜测值,请重试')
tr+=1
elif number==randnum:
打印(f'祝贺你,你猜对了。你花了{tr}次尝试这个')
赢=真
tr=0
除:
打印('这不是一个数字。请重试')
tr+=1
也许有人也面临这个问题,知道如何解决它

@dp.message_handler(lambda message: message.text == "Играть")
async def game(message: types.Message):
    await message.reply('Number guesses')
    win = False
    number = random.randint(1, 100)
    tr = 0
    print(number)
    while win != True:
        try:
            @dp.message_handler()
            async def game(message: types.Message):
                if int(message.text) > 100 or int(message.text) < 1:
                    await message.reply('Please enter a number between 1 and 100.')
                    tr += 1
                elif int(message.text) < number:
                    await message.reply('This number is less than the guessed, please try again.')
                    tr += 1
                elif int(message.text) > number:
                    await message.reply('This number is greater than the guessed, please try again.')
                    tr += 1
                elif int(message.text) == number:
                    await message.reply(f'Congratulations, you guessed right. You spent {tr} attempts on this')
                    win = True
                    tr = 0
        except:
            await message.reply('This is not a number. Try again')
            tr += 1
@dp.message\u处理程序(lambda message:message.text==“crmk_Гаа”)
异步def游戏(消息:types.message):
等待消息。回复('数字猜测')
赢=错
number=random.randint(1100)
tr=0
打印(数字)
一边赢正确:
尝试:
@dp.message_handler()
异步def游戏(消息:types.message):
如果int(message.text)>100或int(message.text)<1:
等待消息。答复('请输入一个介于1和100之间的数字')
tr+=1
elif int(message.text)<编号:
等待消息。答复('此数字小于猜测值,请重试')
tr+=1
elif int(message.text)>编号:
等待消息。答复('此数字大于猜测值,请重试')
tr+=1
elif int(message.text)==编号:
等待消息。回复(f'祝贺你,你猜对了。你花了{tr}次尝试这个')
赢=真
tr=0
除:
等待消息。答复('这不是号码。请重试')
tr+=1

对我来说,它很好用。也许这与你如何调用脚本有关?@Justlearnedit也许我不久前刚刚在使用这个模块。你到底是怎么做到的?我将代码复制到一个文件中,并通过终端使用
python3 nums.py
@justlearneddit运行了这个代码吗?就在我为一个机器人重写这个算法时,它对我不起作用,下面是代码。对我来说,它工作得很好。也许这与你如何调用脚本有关?@Justlearnedit也许我不久前刚刚在使用这个模块。你到底是怎么做到的?我将代码复制到一个文件中,并通过终端使用
python3 nums.py
@justlearneddit运行了这个代码吗?当我为一个机器人重写这个算法时,它对我不起作用,下面是代码。