Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -11,43 +11,41 @@ def main():
|
|
11 |
for i in range(num_inputs):
|
12 |
numbers.append(st.number_input(f"Enter number {i+1}", value=0.0, format="%.2f"))
|
13 |
|
14 |
-
operation = st.selectbox("Choose an operation", ["Addition", "Subtraction", "Multiplication", "Division", "Modulus", "Exponentiation
|
15 |
|
16 |
result = numbers[0]
|
17 |
if st.button("Calculate"):
|
18 |
try:
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
result
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
st.error("Cannot perform floor division by zero!")
|
50 |
-
return
|
51 |
|
52 |
st.success(f"Result: {result}")
|
53 |
except Exception as e:
|
|
|
11 |
for i in range(num_inputs):
|
12 |
numbers.append(st.number_input(f"Enter number {i+1}", value=0.0, format="%.2f"))
|
13 |
|
14 |
+
operation = st.selectbox("Choose an operation", ["Addition", "Subtraction", "Multiplication", "Division", "Modulus", "Exponentiation", "Floor Division"])
|
15 |
|
16 |
result = numbers[0]
|
17 |
if st.button("Calculate"):
|
18 |
try:
|
19 |
+
if operation == "Exponentiation":
|
20 |
+
base = st.number_input("Enter the base", value=1.0, format="%.2f")
|
21 |
+
exponent = st.number_input("Enter the exponent", value=1.0, format="%.2f")
|
22 |
+
result = base ** exponent
|
23 |
+
else:
|
24 |
+
for index, num in enumerate(numbers[1:]):
|
25 |
+
if operation == "Addition":
|
26 |
+
result += num
|
27 |
+
elif operation == "Subtraction":
|
28 |
+
result -= num
|
29 |
+
elif operation == "Multiplication":
|
30 |
+
result *= num
|
31 |
+
elif operation == "Division":
|
32 |
+
if num != 0:
|
33 |
+
result /= num
|
34 |
+
else:
|
35 |
+
st.error("Cannot divide by zero!")
|
36 |
+
return
|
37 |
+
elif operation == "Modulus":
|
38 |
+
if num != 0:
|
39 |
+
result %= num
|
40 |
+
else:
|
41 |
+
st.error("Cannot find modulus with zero!")
|
42 |
+
return
|
43 |
+
elif operation == "Floor Division":
|
44 |
+
if num != 0:
|
45 |
+
result //= num
|
46 |
+
else:
|
47 |
+
st.error("Cannot perform floor division by zero!")
|
48 |
+
return
|
|
|
|
|
49 |
|
50 |
st.success(f"Result: {result}")
|
51 |
except Exception as e:
|