Spaces:
Build error
Build error
| import streamlit as st | |
| # Functions for basic operations | |
| def add(x, y): | |
| return x + y | |
| def subtract(x, y): | |
| return x - y | |
| def multiply(x, y): | |
| return x * y | |
| def divide(x, y): | |
| if y != 0: | |
| return x / y | |
| else: | |
| return "Error! Division by zero." | |
| # Streamlit app | |
| def calculator(): | |
| st.title("Simple Calculator") | |
| # User input | |
| num1 = st.number_input("Enter first number", value=0.0) | |
| num2 = st.number_input("Enter second number", value=0.0) | |
| # Dropdown for operations | |
| operation = st.selectbox("Choose operation", ["Add", "Subtract", "Multiply", "Divide"]) | |
| # Calculate based on selected operation | |
| if operation == "Add": | |
| result = add(num1, num2) | |
| elif operation == "Subtract": | |
| result = subtract(num1, num2) | |
| elif operation == "Multiply": | |
| result = multiply(num1, num2) | |
| elif operation == "Divide": | |
| result = divide(num1, num2) | |
| # Display the result | |
| st.write(f"Result: {result}") | |
| if __name__ == "__main__": | |
| calculator() | |