Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,36 +4,42 @@ st.set_page_config(page_title="Three-Field Calculator", layout="centered")
|
|
| 4 |
|
| 5 |
st.title("🧮 Three-Field Calculator")
|
| 6 |
|
|
|
|
|
|
|
| 7 |
# Input fields
|
| 8 |
-
num1 = st.number_input("Enter first number", value=0.0, step=0
|
| 9 |
-
num2 = st.number_input("Enter second number", value=0.0, step=0
|
| 10 |
-
num3 = st.number_input("Enter third number", value=0.0, step=0
|
| 11 |
|
| 12 |
# Operation selection
|
| 13 |
operation = st.selectbox(
|
| 14 |
"Select operation",
|
| 15 |
-
|
| 16 |
)
|
| 17 |
|
| 18 |
-
#
|
|
|
|
|
|
|
| 19 |
result = None
|
| 20 |
|
| 21 |
-
if
|
| 22 |
-
|
|
|
|
| 23 |
|
| 24 |
-
elif operation == "Subtraction":
|
| 25 |
-
|
| 26 |
|
| 27 |
-
elif operation == "Multiplication":
|
| 28 |
-
|
|
|
|
|
|
|
| 29 |
|
| 30 |
-
elif operation == "Division":
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
result = None
|
| 36 |
|
| 37 |
-
# Display result
|
| 38 |
-
if result is not None:
|
| 39 |
-
|
|
|
|
| 4 |
|
| 5 |
st.title("🧮 Three-Field Calculator")
|
| 6 |
|
| 7 |
+
st.write("Enter three numbers and choose an operation.")
|
| 8 |
+
|
| 9 |
# Input fields
|
| 10 |
+
num1 = st.number_input("Enter first number", value=0.0, step=1.0)
|
| 11 |
+
num2 = st.number_input("Enter second number", value=0.0, step=1.0)
|
| 12 |
+
num3 = st.number_input("Enter third number", value=0.0, step=1.0)
|
| 13 |
|
| 14 |
# Operation selection
|
| 15 |
operation = st.selectbox(
|
| 16 |
"Select operation",
|
| 17 |
+
("Addition", "Subtraction", "Multiplication", "Division")
|
| 18 |
)
|
| 19 |
|
| 20 |
+
# Calculate button
|
| 21 |
+
calculate = st.button("Calculate")
|
| 22 |
+
|
| 23 |
result = None
|
| 24 |
|
| 25 |
+
if calculate:
|
| 26 |
+
if operation == "Addition":
|
| 27 |
+
result = num1 + num2 + num3
|
| 28 |
|
| 29 |
+
elif operation == "Subtraction":
|
| 30 |
+
result = num1 - num2 - num3
|
| 31 |
|
| 32 |
+
elif operation == "Multiplication":
|
| 33 |
+
result = num1 * num2 * num3
|
| 34 |
+
if num2 == 0 or num3 == 0:
|
| 35 |
+
st.info("Multiplying by zero results in zero.")
|
| 36 |
|
| 37 |
+
elif operation == "Division":
|
| 38 |
+
if num2 == 0 or num3 == 0:
|
| 39 |
+
st.error("Cannot divide by zero. Please enter non-zero values for second and third numbers.")
|
| 40 |
+
else:
|
| 41 |
+
result = num1 / num2 / num3
|
|
|
|
| 42 |
|
| 43 |
+
# Display result
|
| 44 |
+
if result is not None:
|
| 45 |
+
st.success(f"Result: {result}")
|