Помощь в решении проблемы с телеграмм ботом на Python

Почему-то при выборе решения тригонометрических уравнений, выбора функции (не важно какой) при введении аргумента функции и чему она равна через пробел бот никак не реагирует. При этом при решении тригонометрических задач бот отлично функционирует. Совершенно не могу понять в чем проблема, особо не судите если в коде какие-то тупые ошибки я прост не особо в этом разбираюсь еще

import telebot
from telebot import types
from fractions import Fraction
import sympy as sp

bot = telebot.TeleBot(‘Мой токен’)

user_data = {}

@bot.message_handler(commands=[‘start’])
def start(message):
markup = types.InlineKeyboardMarkup()
markup.add(types.InlineKeyboardButton(text=‘Тригонометрические задачи’, callback_data=‘Z’))
markup.add(types.InlineKeyboardButton(text=‘Тригонометрические уравнения’, callback_data=‘U’))
bot.send_message(message.chat.id, ‘Привет! Выбери какой тип задач тебе нужно решить:’, reply_markup=markup)

@bot.callback_query_handler(func=lambda call: call.data == ‘Z’)
def choose_interval(call):
message = call.message
chat_id = message.chat.id
markup2 = types.InlineKeyboardMarkup()
btn1 = types.InlineKeyboardButton(text=‘0<x<π/2 (1 Ч)’, callback_data=‘1’)
btn2 = types.InlineKeyboardButton(text=‘π/2<x<π (2 Ч)’, callback_data=‘2’)
markup2.row(btn1, btn2)
btn3 = types.InlineKeyboardButton(text=‘π<x<3π/2 (3 Ч)’, callback_data=‘3’)
btn4 = types.InlineKeyboardButton(text=‘3π/2<x<2π (4 Ч)’, callback_data=‘4’)
markup2.row(btn3, btn4)
bot.edit_message_text(chat_id=chat_id, message_id=message.message_id, text=‘Выбери чему принадлежит x:’, reply_markup=markup2)

@bot.callback_query_handler(func=lambda call: call.data in [‘1’, ‘2’, ‘3’, ‘4’])
def choose_function(call):
message = call.message
chat_id = message.chat.id
user_data[chat_id] = {‘interval’: call.data}
markup1 = types.InlineKeyboardMarkup()
btn1 = types.InlineKeyboardButton(text=‘sinx’, callback_data=‘sinx’)
btn2 = types.InlineKeyboardButton(text=‘cosx’, callback_data=‘cosx’)
markup1.row(btn1, btn2)
btn3 = types.InlineKeyboardButton(text=‘tgx’, callback_data=‘tgx’)
btn4 = types.InlineKeyboardButton(text=‘ctgx’, callback_data=‘ctgx’)
markup1.row(btn3, btn4)
bot.edit_message_text(chat_id=chat_id, message_id=message.message_id, text=‘Выбери какая функция в дано:’, reply_markup=markup1)

@bot.callback_query_handler(func=lambda call: call.data in [‘sinx’, ‘cosx’, ‘tgx’, ‘ctgx’])
def ask_value(call):
message = call.message
chat_id = message.chat.id
user_data[chat_id][‘function’] = call.data
bot.send_message(chat_id, ‘А теперь напиши чему равна эта функция, если число с корнем то напиши как в примере [K(3)/2], если число целое то напиши дробью, ну а если в знаменателе есть корень то убери корень из знаменателя [1/K(3)=K(3)/3], минус ставить не надо’)

@bot.message_handler(func=lambda message: True)
def echo_message(message):
chat_id = message.chat.id
if chat_id in user_data and ‘function’ in user_data[chat_id]:
try:
value = message.text
interval = user_data[chat_id][‘interval’]
func = user_data[chat_id][‘function’]
if func == ‘sinx’:
sin = value

def process_fraction(fraction_str):
def process_part(part):
part_cleaned = part.replace(‘К’, ‘’).replace(‘K’, ‘’).replace(‘(’, ‘’).replace(‘)’, ‘’)
if ‘К’ in part or ‘K’ in part:
return int(part_cleaned)
else:
return int(part_cleaned) ** 2

num, den = fraction_str.split(‘/’)
numerator_processed = process_part(num)
denominator_processed = process_part(den)
return numerator_processed, denominator_processed

num0, den0 = process_fraction(sin)
sinx = Fraction(num0, den0)

cos = 1 - sinx
c = Fraction(cos)
num1 = c.numerator
den1 = c.denominator
expression = sp.sqrt(sp.Rational(num1, den1))
cosx = sp.simplify(expression)
cosk = str(cosx).replace(‘sqrt’, ‘К’)

tg = sinx / cosx ** 2
t = Fraction(tg)
num2 = t.numerator
den2 = t.denominator
kort = sp.sqrt(sp.Rational(num2, den2))
tgx = sp.simplify(kort)
tgk = str(tgx).replace(‘sqrt’, ‘К’)

ctg = 1 / tgx
ctgk = str(ctg).replace(‘sqrt’, ‘К’)

if interval == ‘1’:
bot.send_message(chat_id, f"sinx = {value}\ncosx = {cosk}\ntanx = {tgk}\nctgx = {ctgk}“)
elif interval == ‘2’:
bot.send_message(chat_id, f"sinx = {value}\ncosx = -{cosk}\ntanx = -{tgk}\nctgx = -{ctgk}”)
elif interval == ‘3’:
bot.send_message(chat_id, f"sinx = -{value}\ncosx = -{cosk}\ntanx = {tgk}\nctgx = {ctgk}“)
elif interval == ‘4’:
bot.send_message(chat_id, f"sinx = -{value}\ncosx = {cosk}\ntanx = -{tgk}\nctgx = -{ctgk}”)

elif func == ‘cosx’:
cos = value

def process_fraction(fraction_str):
def process_part(part):
part_cleaned = part.replace(‘К’, ‘’).replace(‘K’, ‘’).replace(‘(’, ‘’).replace(‘)’, ‘’)
if ‘К’ in part or ‘K’ in part:
return int(part_cleaned)
else:
return int(part_cleaned) ** 2

num, den = fraction_str.split(‘/’)
numerator_processed = process_part(num)
denominator_processed = process_part(den)
return numerator_processed, denominator_processed

num0, den0 = process_fraction(cos)
cosx = Fraction(num0, den0)

sin = 1 - cosx
s = Fraction(sin)
num1 = s.numerator
den1 = s.denominator
expression = sp.sqrt(sp.Rational(num1, den1))
sinx = sp.simplify(expression)
sink = str(sinx).replace(‘sqrt’, ‘К’)

ctg = cosx / (sinx ** 2)
kort = sp.sqrt(ctg)
ctgx = sp.simplify(kort)
ctgk = str(ctgx).replace(‘sqrt’, ‘K’)

tg = 1 / ctgx
tgk = str(tg).replace(‘sqrt’, ‘К’)

if interval == ‘1’:
bot.send_message(chat_id, f"sinx = {sink}\ncosx = {value}\ntanx = {tgk}\nctgx = {ctgk}“)
elif interval == ‘2’:
bot.send_message(chat_id, f"sinx = {sink}\ncosx = -{value}\ntanx = -{tgk}\nctgx = -{ctgk}”)
elif interval == ‘3’:
bot.send_message(chat_id, f"sinx = -{sink}\ncosx = -{value}\ntanx = {tgk}\nctgx = {ctgk}“)
elif interval == ‘4’:
bot.send_message(chat_id, f"sinx = -{sink}\ncosx = {value}\ntanx = -{tgk}\nctgx = -{ctgk}”)

elif func == ‘tgx’:
tg = value

def process_fraction(fraction_str):
def process_part(part):
part_cleaned = part.replace(‘К’, ‘’).replace(‘K’, ‘’).replace(‘(’, ‘’).replace(‘)’, ‘’)
if ‘К’ in part or ‘K’ in part:
return int(part_cleaned)
else:
return int(part_cleaned) ** 2

num, den = fraction_str.split(‘/’)
numerator_processed = process_part(num)
denominator_processed = process_part(den)
return numerator_processed, denominator_processed

num0, den0 = process_fraction(tg)
tgx = Fraction(num0, den0)

ctg = 1 / tgx
ct = Fraction(ctg)
num1 = ct.numerator
den1 = ct.denominator
expression = sp.sqrt(sp.Rational(num1, den1))
ctgx = sp.simplify(expression)
ctgk = str(ctgx).replace(‘sqrt’, ‘К’)

cos = 1 / (1 + tgx)
c = Fraction(cos)
num2 = c.numerator
den2 = c.denominator
expression = sp.sqrt(sp.Rational(num2, den2))
cosx = sp.simplify(expression)
cosk = str(cosx).replace(‘sqrt’, ‘К’)

sin = 1 / (1 + ct)
sinx = sp.sqrt(sin)
sinx = sp.simplify(sinx)
sink = str(sinx).replace(‘sqrt’, ‘К’)

if interval == ‘1’:
bot.send_message(chat_id, f"sinx = {sink}\ncosx = {cosk}\ntanx = {value}\nctgx = {ctgk}“)
elif interval == ‘2’:
bot.send_message(chat_id, f"sinx = {sink}\ncosx = -{cosk}\ntanx = -{value}\nctgx = -{ctgk}”)
elif interval == ‘3’:
bot.send_message(chat_id, f"sinx = -{sink}\ncosx = -{cosk}\ntanx = {value}\nctgx = {ctgk}“)
elif interval == ‘4’:
bot.send_message(chat_id, f"sinx = -{sink}\ncosx = {cosk}\ntanx = -{value}\nctgx = -{ctgk}”)

elif func == ‘ctgx’:
ctg = value

def process_fraction(fraction_str):
def process_part(part):
part_cleaned = part.replace(‘К’, ‘’).replace(‘K’, ‘’).replace(‘(’, ‘’).replace(‘)’, ‘’)
if ‘К’ in part or ‘K’ in part:
return int(part_cleaned)
else:
return int(part_cleaned) ** 2

num, den = fraction_str.split(‘/’)
numerator_processed = process_part(num)
denominator_processed = process_part(den)
return numerator_processed, denominator_processed

num0, den0 = process_fraction(ctg)
ctgx = Fraction(num0, den0)

tg = 1 / ctgx
t = Fraction(tg)
num1 = t.numerator
den1 = t.denominator
expression = sp.sqrt(sp.Rational(num1, den1))
tgx = sp.simplify(expression)
tgk = str(tgx).replace(‘sqrt’, ‘К’)

cos = 1 / (1 + tg)
c = Fraction(cos)
num2 = c.numerator
den2 = c.denominator
expression = sp.sqrt(sp.Rational(num2, den2))
cosx = sp.simplify(expression)
cosk = str(cosx).replace(‘sqrt’, ‘К’)

sin = 1 / (1 + ctgx)
sinx = sp.sqrt(sin)
sinx = sp.simplify(sinx)
sink = str(sinx).replace(‘sqrt’, ‘К’)

if interval == ‘1’:
bot.send_message(chat_id, f"sinx = {sink}\ncosx = {cosk}\ntanx = {tgk}\nctgx = {value}“)
elif interval == ‘2’:
bot.send_message(chat_id, f"sinx = {sink}\ncosx = -{cosk}\ntanx = -{tgk}\nctgx = -{value}”)
elif interval == ‘3’:
bot.send_message(chat_id, f"sinx = -{sink}\ncosx = -{cosk}\ntanx = {tgk}\nctgx = {value}“)
elif interval == ‘4’:
bot.send_message(chat_id, f"sinx = -{sink}\ncosx = {cosk}\ntanx = -{tgk}\nctgx = -{value}”)

except Exception as e:
bot.send_message(chat_id, f"Произошла ошибка: {e}")
else:
bot.send_message(chat_id, “Пожалуйста, выберите функцию и интервал сначала.”)

@bot.callback_query_handler(func=lambda call: call.data == ‘U’)
def choose_function(call):
message = call.message
chat_id = message.chat.id
user_data[chat_id] = {‘interval’: call.data}
markup1 = types.InlineKeyboardMarkup()
btn1 = types.InlineKeyboardButton(text=‘sin’, callback_data=‘sin’)
btn2 = types.InlineKeyboardButton(text=‘cos’, callback_data=‘cos’)
markup1.row(btn1, btn2)
btn3 = types.InlineKeyboardButton(text=‘tg’, callback_data=‘tg’)
btn4 = types.InlineKeyboardButton(text=‘ctg’, callback_data=‘ctg’)
markup1.row(btn3, btn4)
bot.edit_message_text(chat_id=chat_id, message_id=message.message_id, text=‘Выбери какая функция в дано:’, reply_markup=markup1)

@bot.callback_query_handler(func=lambda call: call.data in [‘sin’, ‘cos’, ‘tg’, ‘ctg’])
def ask_value(call):
message = call.message
chat_id = message.chat.id
user_data[chat_id][‘function’] = call.data
bot.send_message(chat_id, ‘Напиши аргумент этой функции и чему она равна, разделив пробелом, если число с корнем то напиши как в примере [K(3)/2], если число целое то напиши дробью, ну а если в знаменателе есть корень то убери корень из знаменателя [1/K(3)=K(3)/3], если есть π то напиши П’)

@bot.message_handler(func=lambda message: True)
def echo_message(message):
chat_id = message.chat.id
if chat_id in user_data and ‘function’ in user_data[chat_id]:
try:
value = message.text
if ’ ’ in value:
x, o = value.split(’ ', 1)
else:
x, o = value, ‘’

def replace_math_symbols(expression):
expression = expression.replace(“К(”, “sqrt(”).replace(“K(”, “sqrt(”)
expression = expression.replace(“П”, “pi”)
return expression

x = replace_math_symbols(x)
o = replace_math_symbols(o)

x2 = sp.symbols(‘x’)
n = sp.symbols(‘n’, integer=True)

if not x:
x1 = 0
else:
x1 = sp.sympify(x)

if not o:
o1 = 0
else:
o1 = sp.sympify(o)

k = o1.coeff(x2)
b = o1.subs(x2, 0)

func = user_data[chat_id][‘function’]

if func == ‘sin’:
arcsin_value = sp.asin(x1)
otv = ((-1) ** n * arcsin_value + sp.pi * n - b) / k

elif func == ‘cos’:
arccos_value = sp.acos(x1)
term1 = sp.simplify((2 * sp.pi * n) / k)
term2 = sp.simplify(-b / k)
otv = f"±{sp.simplify(arccos_value / k)} + {term1 + term2}"

elif func == ‘tg’:
arctg_value = sp.atan(x1)
otv = (arctg_value + sp.pi * n - b) / k

elif func == ‘ctg’:
arcctg_value = sp.acot(x1)
otv = (arcctg_value + sp.pi * n - b) / k

bot.send_message(chat_id, f’x={otv}, n∈Z’)
except Exception as e:
bot.send_message(chat_id, f"Произошла ошибка: {e}")
bot.polling(none_stop=True)