Spaces:
No application file
No application file
streamlit.txt
Browse filesimport
# Run the app
if __name__ == "__main__":
main()
app.py
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import sympy as sp
|
| 3 |
+
|
| 4 |
+
# Function to solve algebraic equations
|
| 5 |
+
def solve_equation(equation):
|
| 6 |
+
lhs, rhs = equation.split("=")
|
| 7 |
+
lhs = sp.sympify(lhs)
|
| 8 |
+
rhs = sp.sympify(rhs)
|
| 9 |
+
solution = sp.solve(lhs - rhs)
|
| 10 |
+
return f"Solution: {solution}"
|
| 11 |
+
|
| 12 |
+
# Function to simplify expressions
|
| 13 |
+
def simplify_expression(expression):
|
| 14 |
+
expr = sp.sympify(expression)
|
| 15 |
+
simplified_expr = sp.simplify(expr)
|
| 16 |
+
return f"Simplified Expression: {simplified_expr}"
|
| 17 |
+
|
| 18 |
+
# Function to factor expressions
|
| 19 |
+
def factor_expression(expression):
|
| 20 |
+
expr = sp.sympify(expression)
|
| 21 |
+
factored_expr = sp.factor(expr)
|
| 22 |
+
return f"Factored Expression: {factored_expr}"
|
| 23 |
+
|
| 24 |
+
# Function to solve basic arithmetic word problems
|
| 25 |
+
def solve_word_problem(operation, num1, num2):
|
| 26 |
+
if operation == "addition":
|
| 27 |
+
result = num1 + num2
|
| 28 |
+
elif operation == "subtraction":
|
| 29 |
+
result = num1 - num2
|
| 30 |
+
elif operation == "multiplication":
|
| 31 |
+
result = num1 * num2
|
| 32 |
+
elif operation == "division":
|
| 33 |
+
if num2 == 0:
|
| 34 |
+
result = "Error! Division by zero."
|
| 35 |
+
else:
|
| 36 |
+
result = num1 / num2
|
| 37 |
+
return f"Result: {result}"
|
| 38 |
+
|
| 39 |
+
# Streamlit Interface
|
| 40 |
+
def main():
|
| 41 |
+
st.title("Math Problem-Solution App")
|
| 42 |
+
|
| 43 |
+
# Tabs for different functionalities
|
| 44 |
+
tab = st.radio("Select a problem type:", ["Solve Algebraic Equation", "Simplify Expression", "Factor Expression", "Solve Word Problem"])
|
| 45 |
+
|
| 46 |
+
if tab == "Solve Algebraic Equation":
|
| 47 |
+
st.header("Solve Algebraic Equation")
|
| 48 |
+
equation_input = st.text_input("Enter an equation (e.g., 2*x + 3 = 5)", "")
|
| 49 |
+
if st.button("Solve Equation"):
|
| 50 |
+
if equation_input:
|
| 51 |
+
solution = solve_equation(equation_input)
|
| 52 |
+
st.write(solution)
|
| 53 |
+
else:
|
| 54 |
+
st.write("Please enter an equation!")
|
| 55 |
+
|
| 56 |
+
elif tab == "Simplify Expression":
|
| 57 |
+
st.header("Simplify Expression")
|
| 58 |
+
expression_input = st.text_input("Enter an expression (e.g., 2*x + 3*x - 4)", "")
|
| 59 |
+
if st.button("Simplify Expression"):
|
| 60 |
+
if expression_input:
|
| 61 |
+
simplified_expr = simplify_expression(expression_input)
|
| 62 |
+
st.write(simplified_expr)
|
| 63 |
+
else:
|
| 64 |
+
st.write("Please enter an expression!")
|
| 65 |
+
|
| 66 |
+
elif tab == "Factor Expression":
|
| 67 |
+
st.header("Factor Expression")
|
| 68 |
+
factor_input = st.text_input("Enter an expression to factor (e.g., x^2 - 5*x + 6)", "")
|
| 69 |
+
if st.button("Factor Expression"):
|
| 70 |
+
if factor_input:
|
| 71 |
+
factored_expr = factor_expression(factor_input)
|
| 72 |
+
st.write(factored_expr)
|
| 73 |
+
else:
|
| 74 |
+
st.write("Please enter an expression!")
|
| 75 |
+
|
| 76 |
+
elif tab == "Solve Word Problem":
|
| 77 |
+
st.header("Solve Word Problem")
|
| 78 |
+
operation = st.selectbox("Choose an operation:", ["addition", "subtraction", "multiplication", "division"])
|
| 79 |
+
num1_input = st.number_input("Enter the first number", 0)
|
| 80 |
+
num2_input = st.number_input("Enter the second number", 0)
|
| 81 |
+
if st.button("Solve Word Problem"):
|
| 82 |
+
result = solve_word_problem(operation, num1_input, num2_input)
|
| 83 |
+
st.write(result)
|
| 84 |
+
|
| 85 |
+
# Run the app
|
| 86 |
+
if __name__ == "__main__":
|
| 87 |
+
main()
|