import streamlit as st import numpy as np # Title of the app st.title("Scientific Calculator") # Input field for numbers num1 = st.number_input("Enter a number", value=0.0, format="%.5f") # Scientific operations operation = st.selectbox("Select Operation", [ "Addition", "Subtraction", "Multiplication", "Division", "Square", "Square Root", "Power", "Logarithm", "Exponential", "Sine", "Cosine", "Tangent", "Factorial" ]) # Additional input if required num2 = None if operation in ["Addition", "Subtraction", "Multiplication", "Division", "Power"]: num2 = st.number_input("Enter second number", value=0.0, format="%.5f") # Perform Calculation result = None if st.button("Calculate"): try: if operation == "Addition": result = num1 + num2 elif operation == "Subtraction": result = num1 - num2 elif operation == "Multiplication": result = num1 * num2 elif operation == "Division": if num2 != 0: result = num1 / num2 else: st.error("Error: Division by zero is not allowed!") elif operation == "Square": result = num1 ** 2 elif operation == "Square Root": if num1 >= 0: result = np.sqrt(num1) else: st.error("Error: Square root of a negative number is not allowed!") elif operation == "Power": result = num1 ** num2 elif operation == "Logarithm": if num1 > 0: result = np.log(num1) else: st.error("Error: Logarithm of zero or a negative number is not allowed!") elif operation == "Exponential": result = np.exp(num1) elif operation == "Sine": result = np.sin(np.radians(num1)) elif operation == "Cosine": result = np.cos(np.radians(num1)) elif operation == "Tangent": result = np.tan(np.radians(num1)) elif operation == "Factorial": if num1 >= 0 and num1 == int(num1): result = np.math.factorial(int(num1)) else: st.error("Error: Factorial is only defined for non-negative integers!") except Exception as e: st.error(f"Error: {e}") # Display Result if result is not None: st.success(f"Result: {result}")