Spaces:
Sleeping
Sleeping
Upload app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
|
| 3 |
+
# Streamlit app title
|
| 4 |
+
st.title("Simple Calculator")
|
| 5 |
+
|
| 6 |
+
# Input fields for numbers
|
| 7 |
+
num1 = st.number_input("Enter the first number", value=0.0, step=1.0)
|
| 8 |
+
num2 = st.number_input("Enter the second number", value=0.0, step=1.0)
|
| 9 |
+
|
| 10 |
+
# Dropdown for selecting operation
|
| 11 |
+
operation = st.selectbox("Select an operation", ["Addition", "Subtraction", "Multiplication", "Division"])
|
| 12 |
+
|
| 13 |
+
# Perform calculation based on selected operation
|
| 14 |
+
result = None
|
| 15 |
+
if st.button("Calculate"):
|
| 16 |
+
if operation == "Addition":
|
| 17 |
+
result = num1 + num2
|
| 18 |
+
elif operation == "Subtraction":
|
| 19 |
+
result = num1 - num2
|
| 20 |
+
elif operation == "Multiplication":
|
| 21 |
+
result = num1 * num2
|
| 22 |
+
elif operation == "Division":
|
| 23 |
+
if num2 != 0:
|
| 24 |
+
result = num1 / num2
|
| 25 |
+
else:
|
| 26 |
+
st.error("Division by zero is not allowed!")
|
| 27 |
+
|
| 28 |
+
# Display the result
|
| 29 |
+
if result is not None:
|
| 30 |
+
st.success(f"The result is: {result}")
|