ghaffarmumtat123 commited on
Commit
258ff35
·
verified ·
1 Parent(s): 86263db

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -23
app.py CHANGED
@@ -3,38 +3,54 @@ 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():
 
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():