Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,31 +1,70 @@
|
|
| 1 |
import streamlit as st
|
|
|
|
| 2 |
|
| 3 |
# Title of the application
|
| 4 |
-
st.title('
|
| 5 |
|
| 6 |
-
# Sidebar for
|
| 7 |
operation = st.sidebar.selectbox(
|
| 8 |
"Choose operation",
|
| 9 |
-
("
|
| 10 |
)
|
| 11 |
|
| 12 |
-
# User input for
|
| 13 |
-
num1 = st.number_input('Enter first number', value=0)
|
| 14 |
-
num2 = st.number_input('Enter second number', value=0)
|
| 15 |
-
|
| 16 |
-
#
|
| 17 |
-
if
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
result = num1
|
| 27 |
-
|
| 28 |
-
result =
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
import math
|
| 3 |
|
| 4 |
# Title of the application
|
| 5 |
+
st.title('Advanced Calculator')
|
| 6 |
|
| 7 |
+
# Sidebar for choosing operation
|
| 8 |
operation = st.sidebar.selectbox(
|
| 9 |
"Choose operation",
|
| 10 |
+
("Basic", "Advanced", "Trigonometric", "Logarithmic", "Factorial", "Percentage", "Memory")
|
| 11 |
)
|
| 12 |
|
| 13 |
+
# User input for numbers
|
| 14 |
+
num1 = st.number_input('Enter first number', value=0.0)
|
| 15 |
+
num2 = st.number_input('Enter second number (optional)', value=0.0)
|
| 16 |
+
|
| 17 |
+
# Memory variable (to store previous result)
|
| 18 |
+
if 'memory' not in st.session_state:
|
| 19 |
+
st.session_state.memory = 0.0
|
| 20 |
+
|
| 21 |
+
# Basic Operations
|
| 22 |
+
if operation == "Basic":
|
| 23 |
+
basic_op = st.selectbox("Choose basic operation", ("Add", "Subtract", "Multiply", "Divide"))
|
| 24 |
+
if basic_op == "Add":
|
| 25 |
+
result = num1 + num2
|
| 26 |
+
elif basic_op == "Subtract":
|
| 27 |
+
result = num1 - num2
|
| 28 |
+
elif basic_op == "Multiply":
|
| 29 |
+
result = num1 * num2
|
| 30 |
+
elif basic_op == "Divide":
|
| 31 |
+
if num2 != 0:
|
| 32 |
+
result = num1 / num2
|
| 33 |
+
else:
|
| 34 |
+
result = "Error: Division by Zero"
|
| 35 |
+
|
| 36 |
+
# Advanced Operations
|
| 37 |
+
elif operation == "Advanced":
|
| 38 |
+
advanced_op = st.selectbox("Choose advanced operation", ("Power", "Square Root"))
|
| 39 |
+
if advanced_op == "Power":
|
| 40 |
+
result = num1 ** num2
|
| 41 |
+
elif advanced_op == "Square Root":
|
| 42 |
+
if num1 >= 0:
|
| 43 |
+
result = math.sqrt(num1)
|
| 44 |
+
else:
|
| 45 |
+
result = "Error: Cannot take square root of negative number"
|
| 46 |
+
|
| 47 |
+
# Trigonometric Operations
|
| 48 |
+
elif operation == "Trigonometric":
|
| 49 |
+
trig_op = st.selectbox("Choose trigonometric function", ("Sine", "Cosine", "Tangent"))
|
| 50 |
+
angle_in_degrees = st.checkbox("Use degrees instead of radians?")
|
| 51 |
+
|
| 52 |
+
if trig_op == "Sine":
|
| 53 |
+
if angle_in_degrees:
|
| 54 |
+
result = math.sin(math.radians(num1))
|
| 55 |
+
else:
|
| 56 |
+
result = math.sin(num1)
|
| 57 |
+
elif trig_op == "Cosine":
|
| 58 |
+
if angle_in_degrees:
|
| 59 |
+
result = math.cos(math.radians(num1))
|
| 60 |
+
else:
|
| 61 |
+
result = math.cos(num1)
|
| 62 |
+
elif trig_op == "Tangent":
|
| 63 |
+
if angle_in_degrees:
|
| 64 |
+
result = math.tan(math.radians(num1))
|
| 65 |
+
else:
|
| 66 |
+
result = math.tan(num1)
|
| 67 |
+
|
| 68 |
+
# Logarithmic Operations
|
| 69 |
+
elif operation == "Logarithmic":
|
| 70 |
+
log_op = st.selectbox("Choose logarithmic operation",
|