Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,32 +1,61 @@
|
|
| 1 |
import streamlit as st
|
|
|
|
| 2 |
|
| 3 |
-
st.set_page_config(page_title="
|
| 4 |
-
|
| 5 |
-
st.title("🧮 Simple Calculator")
|
| 6 |
-
st.write("This is a basic calculator built with Streamlit.")
|
| 7 |
-
|
| 8 |
-
# Input fields
|
| 9 |
-
num1 = st.number_input("Enter first number:", format="%.2f")
|
| 10 |
-
num2 = st.number_input("Enter second number:", format="%.2f")
|
| 11 |
|
| 12 |
# Operation selection
|
| 13 |
-
operation = st.selectbox("
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
-
# Perform calculation
|
| 16 |
result = None
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
|
| 30 |
# Display result
|
| 31 |
if result is not None:
|
| 32 |
-
st.success(f"Result: {result}")
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
import numpy as np
|
| 3 |
|
| 4 |
+
st.set_page_config(page_title="Advanced Calculator", page_icon="🧮")
|
| 5 |
+
st.title("🧮 Advanced Calculator")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
# Operation selection
|
| 8 |
+
operation = st.selectbox("Choose an operation:", [
|
| 9 |
+
"Addition", "Subtraction", "Multiplication", "Division",
|
| 10 |
+
"Power", "Modulus", "Square Root", "Logarithm",
|
| 11 |
+
"Sine", "Cosine", "Tangent"
|
| 12 |
+
])
|
| 13 |
|
|
|
|
| 14 |
result = None
|
| 15 |
+
|
| 16 |
+
# Input fields and operation logic
|
| 17 |
+
if operation in ["Addition", "Subtraction", "Multiplication", "Division", "Power", "Modulus"]:
|
| 18 |
+
num1 = st.number_input("Enter first number:", format="%.4f")
|
| 19 |
+
num2 = st.number_input("Enter second number:", format="%.4f")
|
| 20 |
+
|
| 21 |
+
if st.button("Calculate"):
|
| 22 |
+
if operation == "Addition":
|
| 23 |
+
result = num1 + num2
|
| 24 |
+
elif operation == "Subtraction":
|
| 25 |
+
result = num1 - num2
|
| 26 |
+
elif operation == "Multiplication":
|
| 27 |
+
result = num1 * num2
|
| 28 |
+
elif operation == "Division":
|
| 29 |
+
if num2 != 0:
|
| 30 |
+
result = num1 / num2
|
| 31 |
+
else:
|
| 32 |
+
st.error("Cannot divide by zero.")
|
| 33 |
+
elif operation == "Power":
|
| 34 |
+
result = np.power(num1, num2)
|
| 35 |
+
elif operation == "Modulus":
|
| 36 |
+
result = num1 % num2
|
| 37 |
+
|
| 38 |
+
elif operation in ["Square Root", "Logarithm", "Sine", "Cosine", "Tangent"]:
|
| 39 |
+
num = st.number_input("Enter the number:", format="%.4f")
|
| 40 |
+
|
| 41 |
+
if st.button("Calculate"):
|
| 42 |
+
if operation == "Square Root":
|
| 43 |
+
if num >= 0:
|
| 44 |
+
result = np.sqrt(num)
|
| 45 |
+
else:
|
| 46 |
+
st.error("Cannot take square root of a negative number.")
|
| 47 |
+
elif operation == "Logarithm":
|
| 48 |
+
if num > 0:
|
| 49 |
+
result = np.log10(num)
|
| 50 |
+
else:
|
| 51 |
+
st.error("Logarithm undefined for non-positive numbers.")
|
| 52 |
+
elif operation == "Sine":
|
| 53 |
+
result = np.sin(np.radians(num))
|
| 54 |
+
elif operation == "Cosine":
|
| 55 |
+
result = np.cos(np.radians(num))
|
| 56 |
+
elif operation == "Tangent":
|
| 57 |
+
result = np.tan(np.radians(num))
|
| 58 |
|
| 59 |
# Display result
|
| 60 |
if result is not None:
|
| 61 |
+
st.success(f"Result: {result:.4f}")
|