Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
|
3 |
+
# Title of the app
|
4 |
+
st.title("Simple Calculator")
|
5 |
+
|
6 |
+
# Input fields for the two numbers
|
7 |
+
num1 = st.number_input("Enter the first number:", value=0.0)
|
8 |
+
num2 = st.number_input("Enter the second number:", value=0.0)
|
9 |
+
|
10 |
+
# Dropdown for selecting the operation
|
11 |
+
operation = st.selectbox("Select operation:", ["Add", "Subtract", "Multiply", "Divide"])
|
12 |
+
|
13 |
+
# Button to calculate the result
|
14 |
+
if st.button("Calculate"):
|
15 |
+
if operation == "Add":
|
16 |
+
result = num1 + num2
|
17 |
+
elif operation == "Subtract":
|
18 |
+
result = num1 - num2
|
19 |
+
elif operation == "Multiply":
|
20 |
+
result = num1 * num2
|
21 |
+
elif operation == "Divide":
|
22 |
+
if num2 != 0:
|
23 |
+
result = num1 / num2
|
24 |
+
else:
|
25 |
+
result = "Cannot divide by zero!"
|
26 |
+
|
27 |
+
# Display the result
|
28 |
+
st.write(f"Result: {result}")
|
29 |
+
|
30 |
+
# Footer
|
31 |
+
st.write("Made with Streamlit")
|
32 |
+
|