Update app.py
Browse files
app.py
CHANGED
@@ -1,31 +1,56 @@
|
|
1 |
import streamlit as st
|
|
|
2 |
|
3 |
-
st.set_page_config(page_title="
|
4 |
|
5 |
-
st.title("🧮
|
6 |
|
7 |
-
#
|
8 |
-
|
9 |
-
|
|
|
|
|
|
|
|
|
|
|
10 |
|
11 |
# Operation selection
|
12 |
-
operation = st.selectbox(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
|
14 |
-
#
|
15 |
result = None
|
|
|
16 |
if st.button("Calculate"):
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import streamlit as st
|
2 |
+
import numpy as np
|
3 |
|
4 |
+
st.set_page_config(page_title="Advanced Calculator", page_icon="🧮")
|
5 |
|
6 |
+
st.title("🧮 Advanced Calculator")
|
7 |
|
8 |
+
# Layout
|
9 |
+
col1, col2 = st.columns(2)
|
10 |
+
|
11 |
+
with col1:
|
12 |
+
num1 = st.number_input("Enter first number", format="%.5f", step=1.0)
|
13 |
+
|
14 |
+
with col2:
|
15 |
+
num2 = st.number_input("Enter second number (if needed)", format="%.5f", step=1.0)
|
16 |
|
17 |
# Operation selection
|
18 |
+
operation = st.selectbox(
|
19 |
+
"Choose an operation",
|
20 |
+
[
|
21 |
+
"Add", "Subtract", "Multiply", "Divide",
|
22 |
+
"Power", "Modulo", "Square Root", "Logarithm",
|
23 |
+
"Sine", "Cosine", "Tangent"
|
24 |
+
]
|
25 |
+
)
|
26 |
|
27 |
+
# Perform calculation
|
28 |
result = None
|
29 |
+
|
30 |
if st.button("Calculate"):
|
31 |
+
try:
|
32 |
+
if operation == "Add":
|
33 |
+
result = num1 + num2
|
34 |
+
elif operation == "Subtract":
|
35 |
+
result = num1 - num2
|
36 |
+
elif operation == "Multiply":
|
37 |
+
result = num1 * num2
|
38 |
+
elif operation == "Divide":
|
39 |
+
if num2 != 0:
|
40 |
+
result = num1 / num2
|
41 |
+
else:
|
42 |
+
st.error("Cannot divide by zero.")
|
43 |
+
elif operation == "Power":
|
44 |
+
result = np.power(num1, num2)
|
45 |
+
elif operation == "Modulo":
|
46 |
+
result = num1 % num2
|
47 |
+
elif operation == "Square Root":
|
48 |
+
if num1 >= 0:
|
49 |
+
result = np.sqrt(num1)
|
50 |
+
else:
|
51 |
+
st.error("Cannot take square root of a negative number.")
|
52 |
+
elif operation == "Logarithm":
|
53 |
+
if num1 > 0:
|
54 |
+
result = np.log(num1)
|
55 |
+
else:
|
56 |
+
st.error("Logarithm undefined for non-pos
|