Spaces:
Build error
Build error
| 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() | |