im making a 'guess the number' telegram bot, that is supposed to come up with an integer from 0 to 100. When the user tries to guess the number, bot should give them hints, showing whether their guess is smaller or bigger than the secret number. But it seems to change the secret number every time it recieves a new guess from the user.
Here's the whole code
import random
import telebot
from telebot.types import Message
bot = telebot.TeleBot("-token-")
@bot.message_handler(commands = ('start'))
def guess_number():
a = random.randint(0,100)
a = guess_number.variable
def send_welcome(message):
bot.send_message(message.chat.id, "you entered a guessing game, traveller. Guess a number from 0 to 100, or be eaten by a dragon.")
@bot.message_handler(func=lambda message: True)
def checking(message):
try:
user_message = int(message.text)
if user_message > guess_number.variable:
bot.send_message(message.chat.id, "your number is greater than mine")
elif user_message < guess_number.variable:
bot.send_message(message.chat.id, "your number is smaller than mine")
else:
bot.send_message(message.chat.id, "yep, that's the right number")
except ValueError:
bot.send_message(message.chat.id, "you must enter an integer")
bot.polling()
a = random.randint(0,100) a = guess_number.variable
also it says that the variable 'a',
which is a store for the secret number, is out of reach in guess_number function.
I believe that the variable should be put somewhere else, but can't
figure out where exactly.