Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
|
| 3 |
+
# Configure the page
|
| 4 |
+
st.set_page_config(page_title="Simple Calculator", page_icon="🧮")
|
| 5 |
+
|
| 6 |
+
# Set the title of the app
|
| 7 |
+
st.title("🧮 Simple Calculator")
|
| 8 |
+
|
| 9 |
+
# Input fields for numbers
|
| 10 |
+
number1 = st.number_input("Enter the first number", value=0.0)
|
| 11 |
+
number2 = st.number_input("Enter the second number", value=0.0)
|
| 12 |
+
|
| 13 |
+
# Dropdown to select operation
|
| 14 |
+
operation = st.selectbox("Select an operation", ["Add", "Subtract", "Multiply", "Divide"])
|
| 15 |
+
|
| 16 |
+
# Calculate button
|
| 17 |
+
if st.button("Calculate"):
|
| 18 |
+
# Perform the selected operation
|
| 19 |
+
if operation == "Add":
|
| 20 |
+
result = number1 + number2
|
| 21 |
+
elif operation == "Subtract":
|
| 22 |
+
result = number1 - number2
|
| 23 |
+
elif operation == "Multiply":
|
| 24 |
+
result = number1 * number2
|
| 25 |
+
elif operation == "Divide":
|
| 26 |
+
if number2 == 0:
|
| 27 |
+
st.error("Error: Division by zero is not allowed!")
|
| 28 |
+
result = None
|
| 29 |
+
else:
|
| 30 |
+
result = number1 / number2
|
| 31 |
+
|
| 32 |
+
# Display the result if no error
|
| 33 |
+
if result is not None:
|
| 34 |
+
st.success(f"Result: **{result:.2f}**")
|