@bot.message_handler()
def info(message):
if message.text.lower() == 'да':
dictionary = {}
with open('ENRUS1.TXT', 'r', encoding='cp1251') as file:
lines = file.readlines()
for i in range(0, len(lines), 2):
english_word = lines[i].strip()
russian_translation = lines[i + 1].strip()
dictionary[english_word] = russian_translation
english_word = random.choice(list(dictionary.keys()))
correct_translation = dictionary[english_word]
bot.send_message(message.chat.id, f'Переведите слово {english_word}')
bot.register_next_step_handler(message, on_anser, correct_translation, english_word)
def on_anser(message, correct_translation, english_word):
attempts = 3
for i in range(attempts):
user_translation = message.text.lower()
user_words = user_translation.split()
correct_words = set(correct_translation.lower().split())
is_correct = any(word in correct_words for word in user_words)
english_word1 = english_word.split()
if is_correct and len(user_words) == len(english_word1):
bot.send_message(message.chat.id, f'Верно')
bot.register_next_step_handler(message, on_anser, correct_translation, english_word)
else:
if attempts - i - 1 != 0:
bot.send_message(message.chat.id, f'Неверно! Осталось {attempts - i - 1} попытки')
if attempts - i - 1 == 0:
bot.send_message(message.chat.id, f'Неверно. Правильный перевод: {correct_translation}')