Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
|
3 |
+
def main():
|
4 |
+
st.title("Simple Calculator")
|
5 |
+
|
6 |
+
# User inputs
|
7 |
+
num1 = st.number_input("Enter first number", value=0.0, format="%.2f")
|
8 |
+
num2 = st.number_input("Enter second number", value=0.0, format="%.2f")
|
9 |
+
operation = st.selectbox("Select operation", ["Addition", "Subtraction", "Multiplication", "Division"])
|
10 |
+
|
11 |
+
result = None
|
12 |
+
|
13 |
+
if st.button("Calculate"):
|
14 |
+
if operation == "Addition":
|
15 |
+
result = num1 + num2
|
16 |
+
elif operation == "Subtraction":
|
17 |
+
result = num1 - num2
|
18 |
+
elif operation == "Multiplication":
|
19 |
+
result = num1 * num2
|
20 |
+
elif operation == "Division":
|
21 |
+
if num2 != 0:
|
22 |
+
result = num1 / num2
|
23 |
+
else:
|
24 |
+
st.error("Cannot divide by zero")
|
25 |
+
|
26 |
+
if result is not None:
|
27 |
+
st.success(f"The result is: {result}")
|
28 |
+
|
29 |
+
if __name__ == "__main__":
|
30 |
+
main()
|