Spaces:
Running
Running
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
|
3 |
+
# Title
|
4 |
+
st.title("🧮 Simple Calculator")
|
5 |
+
|
6 |
+
# User Inputs
|
7 |
+
st.write("Enter two numbers and choose an operation:")
|
8 |
+
num1 = st.number_input("Enter first number", format="%f")
|
9 |
+
num2 = st.number_input("Enter second number", format="%f")
|
10 |
+
|
11 |
+
operation = st.selectbox("Choose operation", ("Add", "Subtract", "Multiply", "Divide"))
|
12 |
+
|
13 |
+
# Button
|
14 |
+
if st.button("Calculate"):
|
15 |
+
if operation == "Add":
|
16 |
+
result = num1 + num2
|
17 |
+
st.success(f"Result: {result}")
|
18 |
+
elif operation == "Subtract":
|
19 |
+
result = num1 - num2
|
20 |
+
st.success(f"Result: {result}")
|
21 |
+
elif operation == "Multiply":
|
22 |
+
result = num1 * num2
|
23 |
+
st.success(f"Result: {result}")
|
24 |
+
elif operation == "Divide":
|
25 |
+
if num2 != 0:
|
26 |
+
result = num1 / num2
|
27 |
+
st.success(f"Result: {result}")
|
28 |
+
else:
|
29 |
+
st.error("Division by zero is not allowed.")
|