Hi all,
I was hoping the community could help me with an error I am getting with the dictionary ‘questions’ (I am a newbie, so any help would be much appreciated).
See the whole code, then see the screenshot of the code so that you can find where the errors are at lines 20 and 24:
#START
bot = telebot.TeleBot(‘******************************************’)
@bot.message_handler(commands=[‘start’])
def start_message(message):
bot.reply_to(message, “Welcome to the Quiz Bot! Please answer the following questions:”)
# Questions and answers stored in a dictionary
questions = {
“What is the answer of question 1”: “A”,
“What is the answer of question 2”: “B”,
“What is the answer of question 3”: “C”
}
# Start the question answering loop
current_question = next(iter(questions))
bot.send_message(message.chat.id, current_question)
@bot.message_handler(func=lambda message: True)
def answer_question(message):
global current_question
# Check if the user’s answer is correct for the current question
correct_answer = questions[current_question]
if message.text.lower() == correct_answer.lower():
bot.reply_to(message, “Correct!”)
# Move on to the next question
current_question = next(iter(questions), None)
if current_question:
bot.send_message(message.chat.id, current_question)
else:
bot.send_message(message.chat.id, “Congratulations! You have answered all the questions correctly.”)
else:
bot.reply_to(message, "Incorrect. The answer is " + correct_answer + “.”)
bot.polling()
#STOP