Henry Crafer
Henry Crafer

Reputation: 13

Solving algebra equations in python

I'm new to programming and I'm having a hard time solving this equation using Python. I would like for the system to give me the value for X. ((X-5)/(2) + (X/4) + (X-12)/(3))

Upvotes: 1

Views: 351

Answers (2)

imranal
imranal

Reputation: 656

Assuming your right hand side of equation is some given value or expression:

import sympy as sym
x = sym.Symbol("x")
RHS = 13
LHS = (x - 5)/2 + x/4 + (x - 12)/3
eqn = LHS - RHS
soln = sym.solve(eqn, x)
print(soln)

This yields the solution x = 18. Replace RHS with your own value or expression. If there is nothing, simply put RHS to be 0; which gives the solution x = 6.

If you want to solve your equation step by step, you are still going to need SymPy:

https://docs.sympy.org/latest/install.html

Upvotes: 0

Rusty Widebottom
Rusty Widebottom

Reputation: 984

Sympy looks promising, especially section 3.2.4, "Equation Solving".

Upvotes: 0

Related Questions