Spaces:
Build error
Build error
File size: 2,189 Bytes
efa2144 df0aef2 efa2144 df0aef2 efa2144 df0aef2 efa2144 eb81aab df0aef2 efa2144 df0aef2 eb81aab df0aef2 efa2144 df0aef2 efa2144 597263c | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | import streamlit as st
def main():
st.title("Advanced Calculator")
# Number of inputs
num_inputs = st.number_input("Enter the number of inputs", min_value=2, max_value=10, value=2, step=1)
# User inputs
numbers = []
for i in range(num_inputs):
numbers.append(st.number_input(f"Enter number {i+1}", value=0.0, format="%.2f"))
operation = st.selectbox("Choose an operation", ["Addition", "Subtraction", "Multiplication", "Division", "Modulus", "Exponentiation", "Floor Division"])
result = numbers[0]
if st.button("Calculate"):
try:
if operation == "Exponentiation":
base = st.number_input("Enter the base", value=1.0, format="%.2f")
exponent = st.number_input("Enter the exponent", value=1.0, format="%.2f")
result = base ** exponent
else:
for index, num in enumerate(numbers[1:]):
if operation == "Addition":
result += num
elif operation == "Subtraction":
result -= num
elif operation == "Multiplication":
result *= num
elif operation == "Division":
if num != 0:
result /= num
else:
st.error("Cannot divide by zero!")
return
elif operation == "Modulus":
if num != 0:
result %= num
else:
st.error("Cannot find modulus with zero!")
return
elif operation == "Floor Division":
if num != 0:
result //= num
else:
st.error("Cannot perform floor division by zero!")
return
st.success(f"Result: {result}")
except Exception as e:
st.error(f"An error occurred: {e}")
if __name__ == "__main__":
main()
|