Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,4 +1,58 @@
|
|
1 |
import streamlit as st
|
2 |
|
3 |
-
|
4 |
-
st.write(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import streamlit as st
|
2 |
|
3 |
+
st.title("Simple Calculator")
|
4 |
+
st.write("This calculator performs basic arithmetic operations.")
|
5 |
+
|
6 |
+
# Input fields for the numbers
|
7 |
+
num1 = st.number_input("Enter 1st number:", value=0.0)
|
8 |
+
num2 = st.number_input("Enter 2nd number:", value=0.0)
|
9 |
+
|
10 |
+
# Operation selection
|
11 |
+
operation = st.selectbox(
|
12 |
+
"Select operation:",("Addition", "Substraction", "Multiplication", "Division", "Exponentiation")
|
13 |
+
)
|
14 |
+
|
15 |
+
# Calculate button
|
16 |
+
if st.button("Calculate"):
|
17 |
+
if operation == "Addition":
|
18 |
+
result = num1 + num2
|
19 |
+
st.success(f"{num1} - {num2} = {result}")
|
20 |
+
|
21 |
+
elif operation == "Substraction":
|
22 |
+
result = num1 - num2
|
23 |
+
st.success(f"{num1} - {num2} = {result}")
|
24 |
+
|
25 |
+
elif operation == "Multiplication":
|
26 |
+
result = num1 * num2
|
27 |
+
st.success(f"{num1} * {num2} = {result}")
|
28 |
+
|
29 |
+
elif operation == "Division":
|
30 |
+
if num2 == 0:
|
31 |
+
st.error("Error: Division by zero!")
|
32 |
+
else:
|
33 |
+
result = num1 / num2
|
34 |
+
st.success(f"{num1} / {num2} = {result}")
|
35 |
+
|
36 |
+
elif operation == "Exponentiation":
|
37 |
+
result = num1 ** num2
|
38 |
+
st.success(f"{num1} ^ {num2} = {result}")
|
39 |
+
|
40 |
+
# Add a divider and display instructions
|
41 |
+
st.divider()
|
42 |
+
|
43 |
+
# Additional calculator history section
|
44 |
+
st.subheader("History")
|
45 |
+
st.write("Your calculation history will appear here.")
|
46 |
+
|
47 |
+
# How to use section
|
48 |
+
st.subheader("How to Use")
|
49 |
+
st.write("""
|
50 |
+
1. Enter the 1st Number
|
51 |
+
2. Enter the 2nd Number
|
52 |
+
3. Select the operation from the dropdown
|
53 |
+
4. Click the 'Calculate' button
|
54 |
+
""")
|
55 |
+
|
56 |
+
# Footer
|
57 |
+
st.divider()
|
58 |
+
st.caption("Simple Calculator App built with Streamlit")
|