Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -6,16 +6,16 @@ import pandas as pd
|
|
| 6 |
def solve_equation(equation):
|
| 7 |
try:
|
| 8 |
if "=" not in equation:
|
| 9 |
-
return "Invalid input. Please enter an equation with '=' (e.g., 2*x + 3 = 5)."
|
| 10 |
equation = equation.replace("^", "**")
|
| 11 |
equation = equation.replace(" ", "")
|
| 12 |
lhs, rhs = equation.split("=")
|
| 13 |
lhs_expr = sp.sympify(lhs)
|
| 14 |
rhs_expr = sp.sympify(rhs)
|
| 15 |
solution = sp.solve(lhs_expr - rhs_expr)
|
| 16 |
-
return
|
| 17 |
except Exception as e:
|
| 18 |
-
return
|
| 19 |
|
| 20 |
# Function to simplify expressions
|
| 21 |
def simplify_expression(expression):
|
|
@@ -23,9 +23,9 @@ def simplify_expression(expression):
|
|
| 23 |
expression = expression.replace("^", "**")
|
| 24 |
expr = sp.sympify(expression)
|
| 25 |
simplified_expr = sp.simplify(expr)
|
| 26 |
-
return
|
| 27 |
except Exception as e:
|
| 28 |
-
return
|
| 29 |
|
| 30 |
# Function to factor expressions
|
| 31 |
def factor_expression(expression):
|
|
@@ -33,9 +33,9 @@ def factor_expression(expression):
|
|
| 33 |
expression = expression.replace("^", "**")
|
| 34 |
expr = sp.sympify(expression)
|
| 35 |
factored_expr = sp.factor(expr)
|
| 36 |
-
return
|
| 37 |
except Exception as e:
|
| 38 |
-
return
|
| 39 |
|
| 40 |
# Function to solve basic arithmetic word problems
|
| 41 |
def solve_word_problem(operation, num1, num2):
|
|
@@ -51,9 +51,9 @@ def solve_word_problem(operation, num1, num2):
|
|
| 51 |
result = "Error! Division by zero."
|
| 52 |
else:
|
| 53 |
result = num1 / num2
|
| 54 |
-
return
|
| 55 |
except Exception as e:
|
| 56 |
-
return
|
| 57 |
|
| 58 |
# Function to find the factors of a number
|
| 59 |
def find_factors(number):
|
|
@@ -78,8 +78,8 @@ def main():
|
|
| 78 |
equation_input = st.text_input("Enter an equation (e.g., 2*x + 3 = 5)", "")
|
| 79 |
if st.button("Solve Equation"):
|
| 80 |
if equation_input:
|
| 81 |
-
|
| 82 |
-
st.
|
| 83 |
else:
|
| 84 |
st.write("Please enter an equation!")
|
| 85 |
|
|
@@ -88,8 +88,8 @@ def main():
|
|
| 88 |
expression_input = st.text_input("Enter an expression (e.g., 2*x + 3*x - 4)", "")
|
| 89 |
if st.button("Simplify Expression"):
|
| 90 |
if expression_input:
|
| 91 |
-
|
| 92 |
-
st.
|
| 93 |
else:
|
| 94 |
st.write("Please enter an expression!")
|
| 95 |
|
|
@@ -98,8 +98,8 @@ def main():
|
|
| 98 |
factor_input = st.text_input("Enter an expression to factor (e.g., x^2 - 5*x + 6)", "")
|
| 99 |
if st.button("Factor Expression"):
|
| 100 |
if factor_input:
|
| 101 |
-
|
| 102 |
-
st.
|
| 103 |
else:
|
| 104 |
st.write("Please enter an expression!")
|
| 105 |
|
|
@@ -109,8 +109,8 @@ def main():
|
|
| 109 |
num1_input = st.number_input("Enter the first number", 0)
|
| 110 |
num2_input = st.number_input("Enter the second number", 0)
|
| 111 |
if st.button("Solve Word Problem"):
|
| 112 |
-
|
| 113 |
-
st.
|
| 114 |
|
| 115 |
elif tab == "Find Factors of a Number":
|
| 116 |
st.header("Find Factors of a Number")
|
|
|
|
| 6 |
def solve_equation(equation):
|
| 7 |
try:
|
| 8 |
if "=" not in equation:
|
| 9 |
+
return pd.DataFrame([["Invalid input. Please enter an equation with '=' (e.g., 2*x + 3 = 5)."]], columns=["Error"])
|
| 10 |
equation = equation.replace("^", "**")
|
| 11 |
equation = equation.replace(" ", "")
|
| 12 |
lhs, rhs = equation.split("=")
|
| 13 |
lhs_expr = sp.sympify(lhs)
|
| 14 |
rhs_expr = sp.sympify(rhs)
|
| 15 |
solution = sp.solve(lhs_expr - rhs_expr)
|
| 16 |
+
return pd.DataFrame([["Solution", solution]], columns=["Equation", "Solution"])
|
| 17 |
except Exception as e:
|
| 18 |
+
return pd.DataFrame([["Error", str(e)]], columns=["Equation", "Error"])
|
| 19 |
|
| 20 |
# Function to simplify expressions
|
| 21 |
def simplify_expression(expression):
|
|
|
|
| 23 |
expression = expression.replace("^", "**")
|
| 24 |
expr = sp.sympify(expression)
|
| 25 |
simplified_expr = sp.simplify(expr)
|
| 26 |
+
return pd.DataFrame([["Simplified Expression", simplified_expr]], columns=["Expression", "Simplified"])
|
| 27 |
except Exception as e:
|
| 28 |
+
return pd.DataFrame([["Error", str(e)]], columns=["Expression", "Error"])
|
| 29 |
|
| 30 |
# Function to factor expressions
|
| 31 |
def factor_expression(expression):
|
|
|
|
| 33 |
expression = expression.replace("^", "**")
|
| 34 |
expr = sp.sympify(expression)
|
| 35 |
factored_expr = sp.factor(expr)
|
| 36 |
+
return pd.DataFrame([["Factored Expression", factored_expr]], columns=["Expression", "Factored"])
|
| 37 |
except Exception as e:
|
| 38 |
+
return pd.DataFrame([["Error", str(e)]], columns=["Expression", "Error"])
|
| 39 |
|
| 40 |
# Function to solve basic arithmetic word problems
|
| 41 |
def solve_word_problem(operation, num1, num2):
|
|
|
|
| 51 |
result = "Error! Division by zero."
|
| 52 |
else:
|
| 53 |
result = num1 / num2
|
| 54 |
+
return pd.DataFrame([["Operation", operation], ["Result", result]], columns=["Description", "Result"])
|
| 55 |
except Exception as e:
|
| 56 |
+
return pd.DataFrame([["Error", str(e)]], columns=["Description", "Error"])
|
| 57 |
|
| 58 |
# Function to find the factors of a number
|
| 59 |
def find_factors(number):
|
|
|
|
| 78 |
equation_input = st.text_input("Enter an equation (e.g., 2*x + 3 = 5)", "")
|
| 79 |
if st.button("Solve Equation"):
|
| 80 |
if equation_input:
|
| 81 |
+
solution_df = solve_equation(equation_input)
|
| 82 |
+
st.table(solution_df)
|
| 83 |
else:
|
| 84 |
st.write("Please enter an equation!")
|
| 85 |
|
|
|
|
| 88 |
expression_input = st.text_input("Enter an expression (e.g., 2*x + 3*x - 4)", "")
|
| 89 |
if st.button("Simplify Expression"):
|
| 90 |
if expression_input:
|
| 91 |
+
simplified_expr_df = simplify_expression(expression_input)
|
| 92 |
+
st.table(simplified_expr_df)
|
| 93 |
else:
|
| 94 |
st.write("Please enter an expression!")
|
| 95 |
|
|
|
|
| 98 |
factor_input = st.text_input("Enter an expression to factor (e.g., x^2 - 5*x + 6)", "")
|
| 99 |
if st.button("Factor Expression"):
|
| 100 |
if factor_input:
|
| 101 |
+
factored_expr_df = factor_expression(factor_input)
|
| 102 |
+
st.table(factored_expr_df)
|
| 103 |
else:
|
| 104 |
st.write("Please enter an expression!")
|
| 105 |
|
|
|
|
| 109 |
num1_input = st.number_input("Enter the first number", 0)
|
| 110 |
num2_input = st.number_input("Enter the second number", 0)
|
| 111 |
if st.button("Solve Word Problem"):
|
| 112 |
+
result_df = solve_word_problem(operation, num1_input, num2_input)
|
| 113 |
+
st.table(result_df)
|
| 114 |
|
| 115 |
elif tab == "Find Factors of a Number":
|
| 116 |
st.header("Find Factors of a Number")
|