#split the equation into 2 parts using the = sign as the divider, parse, and turn into an equation sympy can understand
equation = Eq(parse_expr(<input string>.split("=")[0]), parse_expr(<input string>.split("=")[1]))
answers = solve(equation)
#check for answers and send them if there are any
if answers.len == 0:
response = "There are no solutions!"
else:
response = "The answers are "
for answer in answers:
response = response + answer + ", "
response = response[:-2]
await self.client.send(response, message.channel)
Я пытался создать диссон-бота, который использовал sympy для решения алгебры, но я продолжал сталкиваться с ошибками при реализации выше. Может кто-нибудь помочь, пожалуйста?
Но для ввода 10 = 2x
parse_expr
выдает синтаксическую ошибку. Как я могу использовать parse_expr
или подобную функцию для принятия выражений такого типа?
Ошибка:
File "C:\Users\RealAwesomeness\Documents\Github\amber\amber\plugins/algebra.py", line 19, in respond
equation = Eq(parse_expr(c[2].split("=")[0]),parse_expr(c[2].split("=")[1]))
File "C:\Users\RealAwesomeness\AppData\Local\Programs\Python\Python38-32\lib\site-packages\sympy\parsing\sympy_parser.py", line 1008, in parse_expr
return eval_expr(code, local_dict, global_dict)
File "C:\Users\RealAwesomeness\AppData\Local\Programs\Python\Python38-32\lib\site-packages\sympy\parsing\sympy_parser.py", line 902, in eval_expr
expr = eval(
File "<string>", line 1
Integer (2 )Symbol ('x' )
^
SyntaxError: invalid syntax