get_question_message():
x = randint(0,2)
text = []
my_questions = data['questions'][x]['question']
for index, question in enumerate(my_questions):
text = f"Вопрос №{int(index + 1)}\n\n{question}"
my_answers = data['questions'][x]['answerChoices']
shuffle(my_answers)
my_correct = data['questions'][x]['correctAnswer']
keyboard = telebot.types.InlineKeyboardMarkup()
for answer_index, answer in enumerate(my_answers):
keyboard.row(telebot.types.InlineKeyboardButton(f"{chr(answer_index + 97)}) {answer}",
callback_data=f"?ans&{answer_index}"))
return {
"text": text,
"keyboard": keyboard
}
@bot.callback_query_handler(func=lambda query: query.data == "?next")
def get_answered_message():
question = get_question_message()
text = f"{question['text']}\n"
for answer_index, answer in enumerate(question["my_answers"]):
text += f"{chr(answer_index + 97)}) {answer}"
if answer_index == question["my_correct"]:
text += " ✅"
else:
text += " ❌"
text += "\n"
keyboard = telebot.types.InlineKeyboardMarkup()
keyboard.row(telebot.types.InlineKeyboardButton("Далее", callback_data="?next"))
return {
"text": text,
"keyboard": keyboard
}
выдаёт ошибку: KeyError: 'my_answers'😞
Ну так значит нет такого ключа, не пришёл
Обсуждают сегодня