Search code examples
pythonpython-3.xmathsympylinear-equation

How do I solve linear equation?


Basically, I need to solve the number of classes to be attended to reach a certain percentage. It leaves me with this formula:

required_percentage=(attended+x/conducted+x)*100.

Here, I require "x" as it is the number of classes to be attended.

I tried using sympy module:

import sympy
from sympy.abc import x
sympy.solve(f"(({attended}+x)/({conducted}+x))*100/{required}","x")

But this just constantly gave this answer: [-4]. Upon manual calculation it solves to 30.


Solution

  • x=((required_percentage * conducted)-(100*attended))/(100-required_percentage)

    Got from just manually rearranging the equation for x.