Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,29 +1,77 @@
|
|
| 1 |
import streamlit as st
|
|
|
|
|
|
|
| 2 |
|
| 3 |
def main():
|
| 4 |
-
st.title("
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
st.write(f"### Result: {result}")
|
| 27 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
if __name__ == "__main__":
|
| 29 |
main()
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
import math
|
| 3 |
+
import sympy as sp
|
| 4 |
|
| 5 |
def main():
|
| 6 |
+
st.title("Advanced Calculator")
|
| 7 |
+
|
| 8 |
+
option = st.sidebar.selectbox("Select Calculation Type",
|
| 9 |
+
["Basic Arithmetic", "Algebra", "Trigonometry", "Equation Solver"])
|
| 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":
|
| 18 |
+
result = num1 + num2
|
| 19 |
+
elif operation == "Subtraction":
|
| 20 |
+
result = num1 - num2
|
| 21 |
+
elif operation == "Multiplication":
|
| 22 |
+
result = num1 * num2
|
| 23 |
+
elif operation == "Division":
|
| 24 |
+
result = num1 / num2 if num2 != 0 else "Error: Division by zero"
|
| 25 |
+
|
| 26 |
+
st.write(f"### Result: {result}")
|
| 27 |
+
|
| 28 |
+
elif option == "Algebra":
|
| 29 |
+
st.header("Algebraic Operations")
|
| 30 |
+
expr = st.text_input("Enter an algebraic expression (e.g., x**2 + 3*x - 2)")
|
| 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")
|
| 44 |
+
angle = st.number_input("Enter angle in degrees", value=0.0)
|
| 45 |
+
trig_function = st.selectbox("Choose a function",
|
| 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")
|
| 66 |
+
equation = st.text_input("Enter an equation (e.g., x**2 - 4 = 0)")
|
| 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()
|