Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
|
| 3 |
+
# App Title
|
| 4 |
+
st.title("Simple Calculator")
|
| 5 |
+
|
| 6 |
+
# User Input
|
| 7 |
+
st.header("Enter two numbers")
|
| 8 |
+
num1 = st.number_input("Enter first number:", value=0.0)
|
| 9 |
+
num2 = st.number_input("Enter second number:", value=0.0)
|
| 10 |
+
|
| 11 |
+
# Operation Selection
|
| 12 |
+
operation = st.selectbox(
|
| 13 |
+
"Choose an operation:",
|
| 14 |
+
("Addition", "Subtraction", "Multiplication", "Division")
|
| 15 |
+
)
|
| 16 |
+
|
| 17 |
+
# Calculate Button
|
| 18 |
+
if st.button("Calculate"):
|
| 19 |
+
if operation == "Addition":
|
| 20 |
+
result = num1 + num2
|
| 21 |
+
elif operation == "Subtraction":
|
| 22 |
+
result = num1 - num2
|
| 23 |
+
elif operation == "Multiplication":
|
| 24 |
+
result = num1 * num2
|
| 25 |
+
elif operation == "Division":
|
| 26 |
+
if num2 != 0:
|
| 27 |
+
result = num1 / num2
|
| 28 |
+
else:
|
| 29 |
+
result = "Error! Division by zero."
|
| 30 |
+
|
| 31 |
+
st.success(f"The result of {operation} is: {result}")
|