Created
December 21, 2022 12:54
-
-
Save jabbalaci/51ec3b89d00f156ce659b6bcf582cb11 to your computer and use it in GitHub Desktop.
Solving an equation with Sympy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import sympy | |
from sympy.parsing.sympy_parser import parse_expr | |
def main(): | |
text = "(4 + (2 * (x - 3))) / 4 = 150" | |
equation = "(4 + (2 * (x - 3))) / 4 - 150" | |
p = parse_expr(equation) | |
print(p) | |
x = sympy.Symbol("x") | |
result = sympy.solve(p, x)[0] | |
print("---") | |
print(result) | |
############################################################################## | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This gist belongs to the video https://www.youtube.com/watch?v=uYDEbo4BeMc