Python 如何在此命令中打印随机数?

Python 如何在此命令中打印随机数?,python,telegram-bot,Python,Telegram Bot,我正在用python编写一个电报机器人。我想打印此命令中文本之间的随机数(从1到9,4位数字): import random import telebot from telebot.types import Message TOKEN = '' bot = telebot.TeleBot(TOKEN) @bot.message_handler(commands=['start']) def command_handler(message: Message): bot.reply_t

我正在用python编写一个电报机器人。我想打印此命令中文本之间的随机数(从1到9,4位数字):

import random
import telebot
from telebot.types import Message

TOKEN = ''

bot = telebot.TeleBot(TOKEN)

@bot.message_handler(commands=['start'])
def command_handler(message: Message):
    bot.reply_to(message, 'example_text1\n'
                          random_number_here\n
                          'example_text2\n')
我该怎么做?也许我可以使用另一个命令来执行此操作,但我不知道如何操作。

替换此命令:

'example_text1\n'random_number_here\n'example_text2\n'
为此:

'example_text1\n' + str(random.randint(1, 9999)) + '\nexample_text2\n'

问题已在这里回答: