Python Search Algebra Function

I am trying to make a search function to work with algebra problems. I want something like Wolfram Alpha, but I create a python structure for it. He must be able to calculate many variables and equations on both sides of the equal sign. I recently asked about a validator for a program, so I need a loop that goes through a bunch of numbers and calculates that each of the variables is equal. My problem is decimal. I suggest using the search function. Here is a solution to the equation:

def s_equation(a):
   left, right = a.split('=')
   return eval(left) == eval(right)

Any help would help!

+3
source share
1 answer

eval() , , . , , , Python. , :

# The typical person notation for x-squared isn't valid Python
x^2 + x - 3
# 3x means 3 * x to us, but to python it means nothing
3x + 4
# Some people use % to represent division, but that a modulo operator to Python
3 % 4x
# Python doesn't understand the distributive property
3(4 - x)
# People might use some functions in a way Python doesn't understand
cos x
# Square brackets are used synonymously with parentheses
x[(x^2 - 5)(x^3 - 5x)]

, , - Python. , , , .

, , Python! Python, , .

+1

Source: https://habr.com/ru/post/1773997/


All Articles