Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -15,19 +15,42 @@ def calculate(num1, num2, operation):
|
|
| 15 |
else:
|
| 16 |
return "Invalid operation"
|
| 17 |
|
| 18 |
-
# Streamlit UI
|
| 19 |
-
st.title("Simple Calculator")
|
| 20 |
|
| 21 |
-
#
|
| 22 |
-
|
| 23 |
-
|
|
|
|
|
|
|
| 24 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
operation = st.selectbox(
|
| 26 |
"Select the operation",
|
| 27 |
-
("Add", "Subtract", "Multiply", "Divide")
|
|
|
|
| 28 |
)
|
| 29 |
|
| 30 |
-
#
|
| 31 |
if st.button("Calculate"):
|
| 32 |
result = calculate(num1, num2, operation)
|
| 33 |
-
st.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
else:
|
| 16 |
return "Invalid operation"
|
| 17 |
|
| 18 |
+
# Streamlit UI - Customizing the interface for better user experience
|
|
|
|
| 19 |
|
| 20 |
+
# Title with custom styling
|
| 21 |
+
st.markdown("""
|
| 22 |
+
<h1 style="text-align: center; color: #4CAF50;">Simple Calculator</h1>
|
| 23 |
+
<p style="text-align: center; font-size: 18px;">Perform basic arithmetic operations: Add, Subtract, Multiply, Divide.</p>
|
| 24 |
+
""", unsafe_allow_html=True)
|
| 25 |
|
| 26 |
+
# Create a layout with columns for inputs and result
|
| 27 |
+
col1, col2 = st.columns(2)
|
| 28 |
+
|
| 29 |
+
with col1:
|
| 30 |
+
# User input for the first number
|
| 31 |
+
num1 = st.number_input("Enter the first number", value=0.0, format="%.2f", step=0.1, key="num1")
|
| 32 |
+
|
| 33 |
+
with col2:
|
| 34 |
+
# User input for the second number
|
| 35 |
+
num2 = st.number_input("Enter the second number", value=0.0, format="%.2f", step=0.1, key="num2")
|
| 36 |
+
|
| 37 |
+
# Selectbox for the operation
|
| 38 |
operation = st.selectbox(
|
| 39 |
"Select the operation",
|
| 40 |
+
("Add", "Subtract", "Multiply", "Divide"),
|
| 41 |
+
key="operation"
|
| 42 |
)
|
| 43 |
|
| 44 |
+
# Add a button to calculate
|
| 45 |
if st.button("Calculate"):
|
| 46 |
result = calculate(num1, num2, operation)
|
| 47 |
+
st.markdown(f"### **Result: {result}**", unsafe_allow_html=True)
|
| 48 |
+
|
| 49 |
+
# Additional styling
|
| 50 |
+
st.markdown("""
|
| 51 |
+
<style>
|
| 52 |
+
.css-1v0mbdj {padding: 0.5rem 2rem;}
|
| 53 |
+
.css-1cpxqw2 {background-color: #4CAF50; color: white;}
|
| 54 |
+
.stButton button {border-radius: 5px;}
|
| 55 |
+
</style>
|
| 56 |
+
""", unsafe_allow_html=True)
|