Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,27 +1,47 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
|
| 3 |
def main():
|
| 4 |
-
st.title("
|
| 5 |
-
st.write("Perform
|
| 6 |
|
| 7 |
# Input fields
|
| 8 |
num1 = st.number_input("Enter the first number", value=0.0, step=1.0)
|
| 9 |
num2 = st.number_input("Enter the second number", value=0.0, step=1.0)
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
# Perform calculation
|
| 13 |
result = None
|
| 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("Division by zero is not allowed!")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
|
| 26 |
# Display result
|
| 27 |
if result is not None:
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
|
| 3 |
def main():
|
| 4 |
+
st.title("Advanced Calculator")
|
| 5 |
+
st.write("Perform arithmetic operations with three numbers")
|
| 6 |
|
| 7 |
# Input fields
|
| 8 |
num1 = st.number_input("Enter the first number", value=0.0, step=1.0)
|
| 9 |
num2 = st.number_input("Enter the second number", value=0.0, step=1.0)
|
| 10 |
+
num3 = st.number_input("Enter the third number", value=0.0, step=1.0)
|
| 11 |
+
operation = st.selectbox("Select an operation", (
|
| 12 |
+
"Addition",
|
| 13 |
+
"Subtraction",
|
| 14 |
+
"Multiplication",
|
| 15 |
+
"Division",
|
| 16 |
+
"Modulus",
|
| 17 |
+
"Exponentiation",
|
| 18 |
+
"Average"
|
| 19 |
+
))
|
| 20 |
|
| 21 |
# Perform calculation
|
| 22 |
result = None
|
| 23 |
if operation == "Addition":
|
| 24 |
+
result = num1 + num2 + num3
|
| 25 |
elif operation == "Subtraction":
|
| 26 |
+
result = num1 - num2 - num3
|
| 27 |
elif operation == "Multiplication":
|
| 28 |
+
result = num1 * num2 * num3
|
| 29 |
elif operation == "Division":
|
| 30 |
+
if num2 != 0 and num3 != 0:
|
| 31 |
+
result = num1 / num2 / num3
|
| 32 |
else:
|
| 33 |
st.error("Division by zero is not allowed!")
|
| 34 |
+
elif operation == "Modulus":
|
| 35 |
+
if num2 != 0 and num3 != 0:
|
| 36 |
+
result = num1 % num2 % num3
|
| 37 |
+
else:
|
| 38 |
+
st.error("Division by zero is not allowed!")
|
| 39 |
+
elif operation == "Exponentiation":
|
| 40 |
+
base = st.number_input("Enter the base number for exponentiation", value=0.0, step=1.0)
|
| 41 |
+
exponent = st.number_input("Enter the exponent", value=1.0, step=1.0)
|
| 42 |
+
result = base ** exponent
|
| 43 |
+
elif operation == "Average":
|
| 44 |
+
result = (num1 + num2 + num3) / 3
|
| 45 |
|
| 46 |
# Display result
|
| 47 |
if result is not None:
|