E
E
Eugene Snow2019-10-12 11:32:05
Python
Eugene Snow, 2019-10-12 11:32:05

I am writing a bot chat game in a telegram in Python - number guessing, how to implement a condition?

Good afternoon, dear Geeks
Help me solve a problem in python, I'm still stupid in programming
The idea is such a telegram bot that plays "guess the number" without unnecessary details
The user enters a number - it is compared with a list in which the range is 1-99
And tells the user - "You are in range" or else "you are not in the range"
I want to solve the issue through the list. Although I agree with the other option.
allowable

list_numeros = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
            12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27,
            28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43,
            44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59,
            60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75,
            76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91,
            92, 93, 94, 95, 96, 97, 98, 99]
start_g_markup = types.InlineKeyboardMarkup(row_width=2)
btn_START = types.InlineKeyboardButton('Начать ИГРУ', callback_data='start_game')
start_g_markup.add(btn_START)
@bot.message_handler(commands=['start', 'help'])
bot.reply_to(message, text="""ЗДЕСЬ ПРАВИЛА и тд Жми начать игру и все будет понятно!""", reply_markup=start_g_markup)

@bot.callback_query_handler(func=lambda call : True)
def cbdata(call) :
    if call.data == "start_game" :
        bot.send_message(call.message.chat.id, "Выбирай ЧИСЛО от 1 до 99")
@bot.message_from_user.id(content_type['text']) - но полагаю что должно быть не текст а int
def sravnenie(message)
       if ##число = числу из списка list_numeros  :   
            bot.reply_to(message, text="""ты в диапазоне 1-99""", reply_markup=start_g_markup)
       elif ##число не равно числу из списка list_numeros :   
            bot.reply_to(message, text="""ты НЕ в диапазоне 1-99""", reply_markup=start_g_markup)

In general, my cycle does not compare anything, it always answers what is after elif, so I erased all the conditions and ask for your help.
Please tell me how to win? So that if the number in the list = True, then he answers it is there and if False, then he answers no, it is not there.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
o5a, 2019-10-12
@mainseo4all

if user_number in list_numeros  :   
            # ...
       else: #elif не нужно, раз других условий больше нет
            # ...

But in general it makes no sense to start a list of a sequence of numbers. Instead, you can immediately compare with range, i.e.
if user_number in range(1,100):

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question