-
Notifications
You must be signed in to change notification settings - Fork 0
/
pruebas.py
25 lines (20 loc) · 1.07 KB
/
pruebas.py
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
from random import randint
from telegram.ext import Updater, CommandHandler, CallbackQueryHandler, CallbackContext
from telegram import InlineKeyboardMarkup, InlineKeyboardButton, Update
def start(update: Update, context: CallbackContext):
a, b = randint(1, 100), randint(1, 100)
update.message.reply_text('{} + {} = ?'.format(a, b),
reply_markup = InlineKeyboardMarkup([[
InlineKeyboardButton(str(s), callback_data = '{} {} {}'.format(a, b, s)) for s in range(a + b - randint(1, 3), a + b + randint(1, 3))
]]))
def answer(update: Update, context: CallbackContext):
a, b, s = [int(x) for x in update.callback_query.data.split()]
if a + b == s:
update.callback_query.edit_message_text('你答對了!')
else:
update.callback_query.edit_message_text('你答錯囉!')
updater = Updater('1375267822:AAEiFLybctSwv647TOeIQYSLX5TGY_fbFQg',use_context=True)
updater.dispatcher.add_handler(CommandHandler('start', start))
updater.dispatcher.add_handler(CallbackQueryHandler(answer))
updater.start_polling()
updater.idle()