-1

I am writing a telegram bot in python. I want to print the random number (from 1 to 9, 4 digit number) between text in this command:

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')

How can I do this? Maybe I can do this using another command, but I don't know how.

Barney
  • 3
  • 1
  • question already answered here: https://stackoverflow.com/questions/2673385/how-to-generate-random-number-with-the-specific-length-in-python – Ramy M. Mousa Mar 10 '19 at 17:42

1 Answers1

0

Replace this:

'example_text1\n'random_number_here\n'example_text2\n'

With this:

'example_text1\n' + str(random.randint(1, 9999)) + '\nexample_text2\n'
jfaccioni
  • 7,099
  • 1
  • 9
  • 25