Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,8 +4,8 @@ import math
|
|
| 4 |
def main():
|
| 5 |
st.title("Ultimate Scientific Calculator")
|
| 6 |
|
| 7 |
-
#
|
| 8 |
-
|
| 9 |
|
| 10 |
# Display supported operations
|
| 11 |
st.markdown("""
|
|
@@ -20,12 +20,14 @@ def main():
|
|
| 20 |
- **Absolute Value (`abs(x)`)** β `abs(-5) = 5`
|
| 21 |
- **Minimum (`min(x, y, ...)`)** β `min(3, 5, 2) = 2`
|
| 22 |
- **Maximum (`max(x, y, ...)`)** β `max(3, 5, 2) = 5`
|
| 23 |
-
- **Sine (`sin(x)`)** β `sin(45) β 0.707` (if
|
| 24 |
-
- **Cosine (`cos(x)`)** β `cos(45) β 0.707` (if
|
| 25 |
-
- **Tangent (`tan(x)`)** β `tan(45) β 1` (if
|
| 26 |
- **Parentheses (`()`)** β Ensures correct order of operations β `(5 + 3) * 2 = 16`
|
| 27 |
|
| 28 |
-
β οΈ **
|
|
|
|
|
|
|
| 29 |
""")
|
| 30 |
|
| 31 |
# User input for mathematical expression
|
|
@@ -33,20 +35,20 @@ def main():
|
|
| 33 |
|
| 34 |
if expression:
|
| 35 |
try:
|
| 36 |
-
#
|
| 37 |
-
def
|
| 38 |
-
return math.sin(math.radians(x)) if
|
| 39 |
|
| 40 |
-
def
|
| 41 |
-
return math.cos(math.radians(x)) if
|
| 42 |
|
| 43 |
-
def
|
| 44 |
-
return math.tan(math.radians(x)) if
|
| 45 |
|
| 46 |
# Safe evaluation using eval with restricted built-in functions
|
| 47 |
result = eval(expression, {"__builtins__": None},
|
| 48 |
{"abs": abs, "min": min, "max": max,
|
| 49 |
-
"sin":
|
| 50 |
|
| 51 |
st.success(f"Result: {result}")
|
| 52 |
except Exception as e:
|
|
|
|
| 4 |
def main():
|
| 5 |
st.title("Ultimate Scientific Calculator")
|
| 6 |
|
| 7 |
+
# User chooses between degrees and radians
|
| 8 |
+
angle_mode = st.radio("Select Angle Mode:", ["Degrees", "Radians"], index=0)
|
| 9 |
|
| 10 |
# Display supported operations
|
| 11 |
st.markdown("""
|
|
|
|
| 20 |
- **Absolute Value (`abs(x)`)** β `abs(-5) = 5`
|
| 21 |
- **Minimum (`min(x, y, ...)`)** β `min(3, 5, 2) = 2`
|
| 22 |
- **Maximum (`max(x, y, ...)`)** β `max(3, 5, 2) = 5`
|
| 23 |
+
- **Sine (`sin(x)`)** β `sin(45) β 0.707` (if Degrees)
|
| 24 |
+
- **Cosine (`cos(x)`)** β `cos(45) β 0.707` (if Degrees)
|
| 25 |
+
- **Tangent (`tan(x)`)** β `tan(45) β 1` (if Degrees)
|
| 26 |
- **Parentheses (`()`)** β Ensures correct order of operations β `(5 + 3) * 2 = 16`
|
| 27 |
|
| 28 |
+
β οΈ **Angle Mode:**
|
| 29 |
+
- If **Degrees Mode is selected**, `sin(45)` is treated as `sin(45Β°)`.
|
| 30 |
+
- If **Radians Mode is selected**, `sin(3.14)` is treated as `sin(3.14 radians)`.
|
| 31 |
""")
|
| 32 |
|
| 33 |
# User input for mathematical expression
|
|
|
|
| 35 |
|
| 36 |
if expression:
|
| 37 |
try:
|
| 38 |
+
# Convert angles to radians if needed
|
| 39 |
+
def sin_angle(x):
|
| 40 |
+
return math.sin(math.radians(x)) if angle_mode == "Degrees" else math.sin(x)
|
| 41 |
|
| 42 |
+
def cos_angle(x):
|
| 43 |
+
return math.cos(math.radians(x)) if angle_mode == "Degrees" else math.cos(x)
|
| 44 |
|
| 45 |
+
def tan_angle(x):
|
| 46 |
+
return math.tan(math.radians(x)) if angle_mode == "Degrees" else math.tan(x)
|
| 47 |
|
| 48 |
# Safe evaluation using eval with restricted built-in functions
|
| 49 |
result = eval(expression, {"__builtins__": None},
|
| 50 |
{"abs": abs, "min": min, "max": max,
|
| 51 |
+
"sin": sin_angle, "cos": cos_angle, "tan": tan_angle})
|
| 52 |
|
| 53 |
st.success(f"Result: {result}")
|
| 54 |
except Exception as e:
|