Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -0,0 +1,63 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import math
|
| 3 |
+
|
| 4 |
+
# Streamlit app title
|
| 5 |
+
st.title("Scientific Calculator")
|
| 6 |
+
|
| 7 |
+
# User input for numbers and operation
|
| 8 |
+
st.subheader("Enter your inputs:")
|
| 9 |
+
|
| 10 |
+
# Input fields
|
| 11 |
+
number1 = st.number_input("Enter the first number:", value=0.0)
|
| 12 |
+
operation = st.selectbox(
|
| 13 |
+
"Choose an operation:",
|
| 14 |
+
["Addition (+)", "Subtraction (-)", "Multiplication (×)", "Division (÷)",
|
| 15 |
+
"Power (^)", "Square Root (√)", "Logarithm (log)", "Sine (sin)",
|
| 16 |
+
"Cosine (cos)", "Tangent (tan)"]
|
| 17 |
+
)
|
| 18 |
+
|
| 19 |
+
# Perform the calculation based on the operation selected
|
| 20 |
+
result = None
|
| 21 |
+
|
| 22 |
+
if operation in ["Addition (+)", "Subtraction (-)", "Multiplication (×)", "Division (÷)", "Power (^)"]:
|
| 23 |
+
number2 = st.number_input("Enter the second number:", value=0.0)
|
| 24 |
+
if operation == "Addition (+)":
|
| 25 |
+
result = number1 + number2
|
| 26 |
+
elif operation == "Subtraction (-)":
|
| 27 |
+
result = number1 - number2
|
| 28 |
+
elif operation == "Multiplication (×)":
|
| 29 |
+
result = number1 * number2
|
| 30 |
+
elif operation == "Division (÷)":
|
| 31 |
+
if number2 != 0:
|
| 32 |
+
result = number1 / number2
|
| 33 |
+
else:
|
| 34 |
+
st.error("Division by zero is not allowed.")
|
| 35 |
+
elif operation == "Power (^)":
|
| 36 |
+
result = number1 ** number2
|
| 37 |
+
|
| 38 |
+
elif operation == "Square Root (√)":
|
| 39 |
+
if number1 >= 0:
|
| 40 |
+
result = math.sqrt(number1)
|
| 41 |
+
else:
|
| 42 |
+
st.error("Square root of a negative number is not defined.")
|
| 43 |
+
elif operation == "Logarithm (log)":
|
| 44 |
+
if number1 > 0:
|
| 45 |
+
base = st.number_input("Enter the base (default is 10):", value=10.0)
|
| 46 |
+
if base > 0 and base != 1:
|
| 47 |
+
result = math.log(number1, base)
|
| 48 |
+
else:
|
| 49 |
+
st.error("Base must be positive and not equal to 1.")
|
| 50 |
+
else:
|
| 51 |
+
st.error("Logarithm of non-positive numbers is not defined.")
|
| 52 |
+
elif operation == "Sine (sin)":
|
| 53 |
+
result = math.sin(math.radians(number1))
|
| 54 |
+
elif operation == "Cosine (cos)":
|
| 55 |
+
result = math.cos(math.radians(number1))
|
| 56 |
+
elif operation == "Tangent (tan)":
|
| 57 |
+
result = math.tan(math.radians(number1))
|
| 58 |
+
|
| 59 |
+
# Display the result
|
| 60 |
+
if result is not None:
|
| 61 |
+
st.subheader("Result:")
|
| 62 |
+
st.write(result)
|
| 63 |
+
|