mjolnir1122 commited on
Commit
93b92dd
·
verified ·
1 Parent(s): f0c812d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -25
app.py CHANGED
@@ -10,8 +10,8 @@ def main():
10
 
11
  if option == "Basic Arithmetic":
12
  st.header("Basic Arithmetic")
13
- num1 = st.number_input("Enter first number", value=0.0)
14
- num2 = st.number_input("Enter second number", value=0.0)
15
  operation = st.selectbox("Choose an operation", ["Addition", "Subtraction", "Multiplication", "Division"])
16
 
17
  if operation == "Addition":
@@ -31,13 +31,16 @@ def main():
31
  variable = st.text_input("Enter the variable (default: x)", value="x")
32
 
33
  if expr:
34
- x = sp.symbols(variable)
35
- expr_sympy = sp.sympify(expr)
 
36
 
37
- st.write("**Simplified Expression:**", sp.simplify(expr_sympy))
38
- st.write("**Expanded Expression:**", sp.expand(expr_sympy))
39
- st.write("**Derivative:**", sp.diff(expr_sympy, x))
40
- st.write("**Integral:**", sp.integrate(expr_sympy, x))
 
 
41
 
42
  elif option == "Trigonometry":
43
  st.header("Trigonometric Functions")
@@ -46,20 +49,23 @@ def main():
46
  ["sin", "cos", "tan", "cot", "sec", "csc"])
47
 
48
  rad = math.radians(angle)
49
- if trig_function == "sin":
50
- result = math.sin(rad)
51
- elif trig_function == "cos":
52
- result = math.cos(rad)
53
- elif trig_function == "tan":
54
- result = math.tan(rad)
55
- elif trig_function == "cot":
56
- result = 1 / math.tan(rad) if math.tan(rad) != 0 else "Undefined"
57
- elif trig_function == "sec":
58
- result = 1 / math.cos(rad) if math.cos(rad) != 0 else "Undefined"
59
- elif trig_function == "csc":
60
- result = 1 / math.sin(rad) if math.sin(rad) != 0 else "Undefined"
 
61
 
62
- st.write(f"### Result: {result}")
 
 
63
 
64
  elif option == "Equation Solver":
65
  st.header("Equation Solver")
@@ -67,11 +73,15 @@ def main():
67
  variable = st.text_input("Enter the variable (default: x)", value="x")
68
 
69
  if equation:
70
- x = sp.symbols(variable)
71
- eq = sp.sympify(equation)
72
- solutions = sp.solve(eq, x)
 
 
73
 
74
- st.write("### Solutions:", solutions)
 
 
75
 
76
  if __name__ == "__main__":
77
  main()
 
10
 
11
  if option == "Basic Arithmetic":
12
  st.header("Basic Arithmetic")
13
+ num1 = st.number_input("Enter first number", value=0.0, format="%.6f")
14
+ num2 = st.number_input("Enter second number", value=0.0, format="%.6f")
15
  operation = st.selectbox("Choose an operation", ["Addition", "Subtraction", "Multiplication", "Division"])
16
 
17
  if operation == "Addition":
 
31
  variable = st.text_input("Enter the variable (default: x)", value="x")
32
 
33
  if expr:
34
+ try:
35
+ x = sp.symbols(variable)
36
+ expr_sympy = sp.sympify(expr)
37
 
38
+ st.write("**Simplified Expression:**", sp.simplify(expr_sympy))
39
+ st.write("**Expanded Expression:**", sp.expand(expr_sympy))
40
+ st.write("**Derivative:**", sp.diff(expr_sympy, x))
41
+ st.write("**Integral:**", sp.integrate(expr_sympy, x))
42
+ except Exception as e:
43
+ st.error(f"Error in algebraic computation: {e}")
44
 
45
  elif option == "Trigonometry":
46
  st.header("Trigonometric Functions")
 
49
  ["sin", "cos", "tan", "cot", "sec", "csc"])
50
 
51
  rad = math.radians(angle)
52
+ try:
53
+ if trig_function == "sin":
54
+ result = math.sin(rad)
55
+ elif trig_function == "cos":
56
+ result = math.cos(rad)
57
+ elif trig_function == "tan":
58
+ result = math.tan(rad)
59
+ elif trig_function == "cot":
60
+ result = 1 / math.tan(rad) if math.tan(rad) != 0 else "Undefined"
61
+ elif trig_function == "sec":
62
+ result = 1 / math.cos(rad) if math.cos(rad) != 0 else "Undefined"
63
+ elif trig_function == "csc":
64
+ result = 1 / math.sin(rad) if math.sin(rad) != 0 else "Undefined"
65
 
66
+ st.write(f"### Result: {result}")
67
+ except Exception as e:
68
+ st.error(f"Error in trigonometric computation: {e}")
69
 
70
  elif option == "Equation Solver":
71
  st.header("Equation Solver")
 
73
  variable = st.text_input("Enter the variable (default: x)", value="x")
74
 
75
  if equation:
76
+ try:
77
+ x = sp.symbols(variable)
78
+ lhs, rhs = equation.split("=")
79
+ eq = sp.Eq(sp.sympify(lhs.strip()), sp.sympify(rhs.strip()))
80
+ solutions = sp.solve(eq, x)
81
 
82
+ st.write("### Solutions:", solutions)
83
+ except Exception as e:
84
+ st.error(f"Error in solving equation: {e}")
85
 
86
  if __name__ == "__main__":
87
  main()