Spaces:
Sleeping
Sleeping
File size: 2,331 Bytes
e63c6c0 41e8de2 e63c6c0 172162e 41e8de2 8c28bb8 09c7fc8 41e8de2 172162e 8c28bb8 41e8de2 8c28bb8 41e8de2 e63c6c0 5adaf02 41e8de2 e63c6c0 5adaf02 8c28bb8 09c7fc8 8c28bb8 09c7fc8 8c28bb8 09c7fc8 8c28bb8 09c7fc8 5adaf02 e63c6c0 09c7fc8 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | import streamlit as st
import math
def main():
st.title("Ultimate Scientific Calculator")
# User chooses between degrees and radians
angle_mode = st.radio("Select Angle Mode:", ["Degrees", "Radians"], index=0)
# Display supported operations
st.markdown("""
## πΉ Supported Operations:
- **Addition (`+`)** β `5 + 3 = 8`
- **Subtraction (`-`)** β `10 - 4 = 6`
- **Multiplication (`*`)** β `7 * 2 = 14`
- **Division (`/`)** β `8 / 2 = 4.0`
- **Exponentiation (`**`)** β `3 ** 2 = 9`
- **Modulus (`%`)** β `10 % 3 = 1`
- **Floor Division (`//`)** β `10 // 3 = 3`
- **Absolute Value (`abs(x)`)** β `abs(-5) = 5`
- **Minimum (`min(x, y, ...)`)** β `min(3, 5, 2) = 2`
- **Maximum (`max(x, y, ...)`)** β `max(3, 5, 2) = 5`
- **Sine (`sin(x)`)** β `sin(45) β 0.707` (if Degrees)
- **Cosine (`cos(x)`)** β `cos(45) β 0.707` (if Degrees)
- **Tangent (`tan(x)`)** β `tan(45) β 1` (if Degrees)
- **Parentheses (`()`)** β Ensures correct order of operations β `(5 + 3) * 2 = 16`
β οΈ **Angle Mode:**
- If **Degrees Mode is selected**, `sin(45)` is treated as `sin(45Β°)`.
- If **Radians Mode is selected**, `sin(3.14)` is treated as `sin(3.14 radians)`.
""")
# User input for mathematical expression
expression = st.text_input("Enter your mathematical expression:", "")
if expression:
try:
# Convert angles to radians if needed
def sin_angle(x):
return math.sin(math.radians(x)) if angle_mode == "Degrees" else math.sin(x)
def cos_angle(x):
return math.cos(math.radians(x)) if angle_mode == "Degrees" else math.cos(x)
def tan_angle(x):
return math.tan(math.radians(x)) if angle_mode == "Degrees" else math.tan(x)
# Safe evaluation using eval with restricted built-in functions
result = eval(expression, {"__builtins__": None},
{"abs": abs, "min": min, "max": max,
"sin": sin_angle, "cos": cos_angle, "tan": tan_angle})
st.success(f"Result: {result}")
except Exception as e:
st.error(f"Error in calculation: {e}")
if __name__ == "__main__":
main()
|