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()