Spaces:
Build error
Build error
| import streamlit as st | |
| import math | |
| # Streamlit app title | |
| st.title("Scientific Calculator") | |
| # User input for numbers and operation | |
| st.subheader("Enter your inputs:") | |
| # Input fields | |
| number1 = st.number_input("Enter the first number:", value=0.0) | |
| operation = st.selectbox( | |
| "Choose an operation:", | |
| ["Addition (+)", "Subtraction (-)", "Multiplication (×)", "Division (÷)", | |
| "Power (^)", "Square Root (√)", "Logarithm (log)", "Sine (sin)", | |
| "Cosine (cos)", "Tangent (tan)"] | |
| ) | |
| # Perform the calculation based on the operation selected | |
| result = None | |
| if operation in ["Addition (+)", "Subtraction (-)", "Multiplication (×)", "Division (÷)", "Power (^)"]: | |
| number2 = st.number_input("Enter the second number:", value=0.0) | |
| if operation == "Addition (+)": | |
| result = number1 + number2 | |
| elif operation == "Subtraction (-)": | |
| result = number1 - number2 | |
| elif operation == "Multiplication (×)": | |
| result = number1 * number2 | |
| elif operation == "Division (÷)": | |
| if number2 != 0: | |
| result = number1 / number2 | |
| else: | |
| st.error("Division by zero is not allowed.") | |
| elif operation == "Power (^)": | |
| result = number1 ** number2 | |
| elif operation == "Square Root (√)": | |
| if number1 >= 0: | |
| result = math.sqrt(number1) | |
| else: | |
| st.error("Square root of a negative number is not defined.") | |
| elif operation == "Logarithm (log)": | |
| if number1 > 0: | |
| base = st.number_input("Enter the base (default is 10):", value=10.0) | |
| if base > 0 and base != 1: | |
| result = math.log(number1, base) | |
| else: | |
| st.error("Base must be positive and not equal to 1.") | |
| else: | |
| st.error("Logarithm of non-positive numbers is not defined.") | |
| elif operation == "Sine (sin)": | |
| result = math.sin(math.radians(number1)) | |
| elif operation == "Cosine (cos)": | |
| result = math.cos(math.radians(number1)) | |
| elif operation == "Tangent (tan)": | |
| result = math.tan(math.radians(number1)) | |
| # Display the result | |
| if result is not None: | |
| st.subheader("Result:") | |
| st.write(result) | |