Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,38 +3,54 @@ import sympy as sp
|
|
| 3 |
|
| 4 |
# Function to solve algebraic equations
|
| 5 |
def solve_equation(equation):
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
# Function to simplify expressions
|
| 13 |
def simplify_expression(expression):
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
# Function to factor expressions
|
| 19 |
def factor_expression(expression):
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
|
|
|
|
|
|
|
|
|
| 23 |
|
| 24 |
# Function to solve basic arithmetic word problems
|
| 25 |
def solve_word_problem(operation, num1, num2):
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
|
|
|
|
|
|
|
|
|
| 38 |
|
| 39 |
# Streamlit Interface
|
| 40 |
def main():
|
|
|
|
| 3 |
|
| 4 |
# Function to solve algebraic equations
|
| 5 |
def solve_equation(equation):
|
| 6 |
+
try:
|
| 7 |
+
# Check if the equation contains "="
|
| 8 |
+
if "=" not in equation:
|
| 9 |
+
return "Invalid input. Please enter an equation with '=' (e.g., 2*x + 3 = 5)."
|
| 10 |
+
|
| 11 |
+
lhs, rhs = equation.split("=")
|
| 12 |
+
lhs = sp.sympify(lhs)
|
| 13 |
+
rhs = sp.sympify(rhs)
|
| 14 |
+
solution = sp.solve(lhs - rhs)
|
| 15 |
+
return f"Solution: {solution}"
|
| 16 |
+
except Exception as e:
|
| 17 |
+
return f"Error: {e}"
|
| 18 |
|
| 19 |
# Function to simplify expressions
|
| 20 |
def simplify_expression(expression):
|
| 21 |
+
try:
|
| 22 |
+
expr = sp.sympify(expression)
|
| 23 |
+
simplified_expr = sp.simplify(expr)
|
| 24 |
+
return f"Simplified Expression: {simplified_expr}"
|
| 25 |
+
except Exception as e:
|
| 26 |
+
return f"Error: {e}"
|
| 27 |
|
| 28 |
# Function to factor expressions
|
| 29 |
def factor_expression(expression):
|
| 30 |
+
try:
|
| 31 |
+
expr = sp.sympify(expression)
|
| 32 |
+
factored_expr = sp.factor(expr)
|
| 33 |
+
return f"Factored Expression: {factored_expr}"
|
| 34 |
+
except Exception as e:
|
| 35 |
+
return f"Error: {e}"
|
| 36 |
|
| 37 |
# Function to solve basic arithmetic word problems
|
| 38 |
def solve_word_problem(operation, num1, num2):
|
| 39 |
+
try:
|
| 40 |
+
if operation == "addition":
|
| 41 |
+
result = num1 + num2
|
| 42 |
+
elif operation == "subtraction":
|
| 43 |
+
result = num1 - num2
|
| 44 |
+
elif operation == "multiplication":
|
| 45 |
+
result = num1 * num2
|
| 46 |
+
elif operation == "division":
|
| 47 |
+
if num2 == 0:
|
| 48 |
+
result = "Error! Division by zero."
|
| 49 |
+
else:
|
| 50 |
+
result = num1 / num2
|
| 51 |
+
return f"Result: {result}"
|
| 52 |
+
except Exception as e:
|
| 53 |
+
return f"Error: {e}"
|
| 54 |
|
| 55 |
# Streamlit Interface
|
| 56 |
def main():
|