Spaces:
Build error
Build error
| import streamlit as st | |
| import math | |
| st.title("Scientific Calculator") | |
| st.sidebar.header("Select Operation") | |
| num1 = st.number_input("Enter first number", value=0.0) | |
| num2 = st.number_input("Enter second number", value=0.0) | |
| operation = st.sidebar.selectbox( | |
| "Select Operation", | |
| ("Add", "Subtract", "Multiply", "Divide", "Sin", "Cos", "Tan", "Log", "Sqrt", "Exp") | |
| ) | |
| def scientific_calculator(num1, num2, operation): | |
| try: | |
| if operation == "Add": | |
| return num1 + num2 | |
| elif operation == "Subtract": | |
| return num1 - num2 | |
| elif operation == "Multiply": | |
| return num1 * num2 | |
| elif operation == "Divide": | |
| return num1 / num2 if num2 != 0 else "Error: Division by zero" | |
| elif operation == "Sin": | |
| return math.sin(math.radians(num1)) | |
| elif operation == "Cos": | |
| return math.cos(math.radians(num1)) | |
| elif operation == "Tan": | |
| return math.tan(math.radians(num1)) | |
| elif operation == "Log": | |
| return math.log(num1) if num1 > 0 else "Error: Log of non-positive number" | |
| elif operation == "Sqrt": | |
| return math.sqrt(num1) if num1 >= 0 else "Error: Negative input for square root" | |
| elif operation == "Exp": | |
| return math.exp(num1) | |
| else: | |
| return "Invalid operation" | |
| except Exception as e: | |
| return f"Error: {e}" | |
| if st.sidebar.button("Calculate"): | |
| result = scientific_calculator(num1, num2, operation) | |
| st.write(f"**Result:** {result}") | |