Spaces:
No application file
No application file
| import streamlit as st | |
| import sympy as sp | |
| # Function to solve algebraic equations | |
| def solve_equation(equation): | |
| lhs, rhs = equation.split("=") | |
| lhs = sp.sympify(lhs) | |
| rhs = sp.sympify(rhs) | |
| solution = sp.solve(lhs - rhs) | |
| return f"Solution: {solution}" | |
| # Function to simplify expressions | |
| def simplify_expression(expression): | |
| expr = sp.sympify(expression) | |
| simplified_expr = sp.simplify(expr) | |
| return f"Simplified Expression: {simplified_expr}" | |
| # Function to factor expressions | |
| def factor_expression(expression): | |
| expr = sp.sympify(expression) | |
| factored_expr = sp.factor(expr) | |
| return f"Factored Expression: {factored_expr}" | |
| # Function to solve basic arithmetic word problems | |
| def solve_word_problem(operation, num1, num2): | |
| if operation == "addition": | |
| result = num1 + num2 | |
| elif operation == "subtraction": | |
| result = num1 - num2 | |
| elif operation == "multiplication": | |
| result = num1 * num2 | |
| elif operation == "division": | |
| if num2 == 0: | |
| result = "Error! Division by zero." | |
| else: | |
| result = num1 / num2 | |
| return f"Result: {result}" | |
| # Streamlit Interface | |
| def main(): | |
| st.title("Math Problem-Solution App") | |
| # Tabs for different functionalities | |
| tab = st.radio("Select a problem type:", ["Solve Algebraic Equation", "Simplify Expression", "Factor Expression", "Solve Word Problem"]) | |
| if tab == "Solve Algebraic Equation": | |
| st.header("Solve Algebraic Equation") | |
| equation_input = st.text_input("Enter an equation (e.g., 2*x + 3 = 5)", "") | |
| if st.button("Solve Equation"): | |
| if equation_input: | |
| solution = solve_equation(equation_input) | |
| st.write(solution) | |
| else: | |
| st.write("Please enter an equation!") | |
| elif tab == "Simplify Expression": | |
| st.header("Simplify Expression") | |
| expression_input = st.text_input("Enter an expression (e.g., 2*x + 3*x - 4)", "") | |
| if st.button("Simplify Expression"): | |
| if expression_input: | |
| simplified_expr = simplify_expression(expression_input) | |
| st.write(simplified_expr) | |
| else: | |
| st.write("Please enter an expression!") | |
| elif tab == "Factor Expression": | |
| st.header("Factor Expression") | |
| factor_input = st.text_input("Enter an expression to factor (e.g., x^2 - 5*x + 6)", "") | |
| if st.button("Factor Expression"): | |
| if factor_input: | |
| factored_expr = factor_expression(factor_input) | |
| st.write(factored_expr) | |
| else: | |
| st.write("Please enter an expression!") | |
| elif tab == "Solve Word Problem": | |
| st.header("Solve Word Problem") | |
| operation = st.selectbox("Choose an operation:", ["addition", "subtraction", "multiplication", "division"]) | |
| num1_input = st.number_input("Enter the first number", 0) | |
| num2_input = st.number_input("Enter the second number", 0) | |
| if st.button("Solve Word Problem"): | |
| result = solve_word_problem(operation, num1_input, num2_input) | |
| st.write(result) | |
| # Run the app | |
| if __name__ == "__main__": | |
| main() | |