Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,48 +2,13 @@
|
|
| 2 |
import streamlit as st
|
| 3 |
import math
|
| 4 |
|
| 5 |
-
st.set_page_config(page_title="Enhanced Calculator", page_icon=":calculator:", layout="wide")
|
| 6 |
|
| 7 |
-
#
|
| 8 |
st.markdown(
|
| 9 |
"""
|
| 10 |
<style>
|
| 11 |
-
|
| 12 |
-
font-family: sans-serif;
|
| 13 |
-
}
|
| 14 |
-
.calculator-container {
|
| 15 |
-
border: 2px solid #ccc;
|
| 16 |
-
padding: 20px;
|
| 17 |
-
border-radius: 10px;
|
| 18 |
-
box-shadow: 5px 5px 10px rgba(0,0,0,0.2); /* Add a subtle shadow */
|
| 19 |
-
background-color: #f8f9fa; /* Light background color */
|
| 20 |
-
}
|
| 21 |
-
.input-col {
|
| 22 |
-
width: 30%; /* Adjust input column width */
|
| 23 |
-
float: left;
|
| 24 |
-
padding: 10px;
|
| 25 |
-
}
|
| 26 |
-
.operation-col {
|
| 27 |
-
width: 40%; /* Adjust operation column width */
|
| 28 |
-
float: left;
|
| 29 |
-
padding: 10px;
|
| 30 |
-
}
|
| 31 |
-
.result-col {
|
| 32 |
-
width: 30%; /* Adjust result column width */
|
| 33 |
-
float: left;
|
| 34 |
-
padding: 10px;
|
| 35 |
-
}
|
| 36 |
-
.stButton>button {
|
| 37 |
-
background-color: #4CAF50; /* Green button */
|
| 38 |
-
color: white;
|
| 39 |
-
padding: 10px 20px;
|
| 40 |
-
border: none;
|
| 41 |
-
border-radius: 5px;
|
| 42 |
-
cursor: pointer;
|
| 43 |
-
}
|
| 44 |
-
.stButton>button:hover {
|
| 45 |
-
background-color: #45a049; /* Darker green on hover */
|
| 46 |
-
}
|
| 47 |
</style>
|
| 48 |
""",
|
| 49 |
unsafe_allow_html=True,
|
|
@@ -51,12 +16,12 @@ st.markdown(
|
|
| 51 |
|
| 52 |
st.title("Enhanced Calculator")
|
| 53 |
|
| 54 |
-
#
|
| 55 |
-
col1, col2, col3 = st.columns([1, 1, 1])
|
| 56 |
|
| 57 |
with col1:
|
| 58 |
st.subheader("Input Numbers")
|
| 59 |
-
num1 = st.number_input("First Number", value=0.0)
|
| 60 |
num2 = st.number_input("Second Number", value=0.0)
|
| 61 |
num3 = st.number_input("Third Number", value=0.0)
|
| 62 |
|
|
@@ -71,15 +36,35 @@ with col3:
|
|
| 71 |
st.subheader("Result")
|
| 72 |
if st.button("Calculate"):
|
| 73 |
try:
|
| 74 |
-
|
| 75 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 76 |
st.write(f"Result: {result}")
|
|
|
|
| 77 |
except (ZeroDivisionError, ValueError) as e:
|
| 78 |
st.error(str(e))
|
| 79 |
except Exception as e:
|
| 80 |
st.error(f"An error occurred: {e}")
|
| 81 |
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
st.
|
| 85 |
-
st.write("Made with Streamlit") # Footer
|
|
|
|
| 2 |
import streamlit as st
|
| 3 |
import math
|
| 4 |
|
| 5 |
+
st.set_page_config(page_title="Enhanced Calculator", page_icon=":calculator:", layout="wide")
|
| 6 |
|
| 7 |
+
# CSS styling (same as before)
|
| 8 |
st.markdown(
|
| 9 |
"""
|
| 10 |
<style>
|
| 11 |
+
/* ... (CSS styles from previous response) ... */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
</style>
|
| 13 |
""",
|
| 14 |
unsafe_allow_html=True,
|
|
|
|
| 16 |
|
| 17 |
st.title("Enhanced Calculator")
|
| 18 |
|
| 19 |
+
# Layout with columns (same as before)
|
| 20 |
+
col1, col2, col3 = st.columns([1, 1, 1])
|
| 21 |
|
| 22 |
with col1:
|
| 23 |
st.subheader("Input Numbers")
|
| 24 |
+
num1 = st.number_input("First Number", value=0.0)
|
| 25 |
num2 = st.number_input("Second Number", value=0.0)
|
| 26 |
num3 = st.number_input("Third Number", value=0.0)
|
| 27 |
|
|
|
|
| 36 |
st.subheader("Result")
|
| 37 |
if st.button("Calculate"):
|
| 38 |
try:
|
| 39 |
+
if operation == "+":
|
| 40 |
+
result = num1 + num2 + num3
|
| 41 |
+
elif operation == "-":
|
| 42 |
+
result = num1 - num2 - num3
|
| 43 |
+
elif operation == "*":
|
| 44 |
+
result = num1 * num2 * num3
|
| 45 |
+
elif operation == "/":
|
| 46 |
+
if num2 == 0 or num3 == 0:
|
| 47 |
+
raise ZeroDivisionError("Division by zero is not allowed.")
|
| 48 |
+
else:
|
| 49 |
+
result = num1 / num2 / num3 # Corrected division
|
| 50 |
+
elif operation == "Power":
|
| 51 |
+
result = num1**num2
|
| 52 |
+
elif operation == "Square Root":
|
| 53 |
+
if num1 < 0:
|
| 54 |
+
raise ValueError("Square root of a negative number is not allowed.")
|
| 55 |
+
else:
|
| 56 |
+
result = math.sqrt(num1)
|
| 57 |
+
elif operation == "Cube Root":
|
| 58 |
+
result = num1**(1/3)
|
| 59 |
+
elif operation == "Average":
|
| 60 |
+
result = (num1 + num2 + num3) / 3
|
| 61 |
st.write(f"Result: {result}")
|
| 62 |
+
|
| 63 |
except (ZeroDivisionError, ValueError) as e:
|
| 64 |
st.error(str(e))
|
| 65 |
except Exception as e:
|
| 66 |
st.error(f"An error occurred: {e}")
|
| 67 |
|
| 68 |
+
# Footer (same as before)
|
| 69 |
+
st.markdown("---")
|
| 70 |
+
st.write("Made with Streamlit")
|
|
|