Spaces:
Sleeping
Sleeping
| import streamlit as st | |
| # Custom CSS for light/dark mode adaptation | |
| st.markdown( | |
| """ | |
| <style> | |
| /* Make the app container responsive */ | |
| .stApp { | |
| max-width: 600px; | |
| margin: auto; | |
| padding: 20px; | |
| border-radius: 10px; | |
| transition: all 0.3s ease-in-out; | |
| } | |
| /* Light Mode Styles */ | |
| @media (prefers-color-scheme: light) { | |
| .stApp { | |
| background-color: #ffffff; | |
| color: #333; | |
| box-shadow: 2px 2px 10px rgba(0,0,0,0.1); | |
| } | |
| .stSelectbox, .stNumberInput { | |
| font-size: 18px; | |
| color: #000; | |
| } | |
| } | |
| /* Dark Mode Styles */ | |
| @media (prefers-color-scheme: dark) { | |
| .stApp { | |
| background-color: #1e1e1e; | |
| color: #ffffff; | |
| box-shadow: 2px 2px 10px rgba(255,255,255,0.1); | |
| } | |
| .stSelectbox, .stNumberInput { | |
| font-size: 18px; | |
| color: #fff; | |
| } | |
| } | |
| .stSuccess { | |
| font-size: 20px; | |
| font-weight: bold; | |
| color: #4CAF50; | |
| } | |
| </style> | |
| """, | |
| unsafe_allow_html=True | |
| ) | |
| def main(): | |
| st.title("📊 Advanced Calculator") | |
| st.write("A simple yet powerful calculator that adapts to your browser theme. Enter your numbers, select an operation, and get instant results!") | |
| # User input for numbers | |
| num1 = st.number_input("Enter first number", value=0.0) | |
| num2 = st.number_input("Enter second number", value=0.0) | |
| num3 = st.number_input("Enter third number", value=0.0) | |
| # Select operation (Dropdown) | |
| operation = st.selectbox( | |
| "Select an operation", | |
| ["Add", "Subtract", "Multiply", "Divide", "Modulus", "Exponentiation", "Average"] | |
| ) | |
| # Perform calculation | |
| result = None | |
| if operation == "Add": | |
| result = num1 + num2 + num3 | |
| elif operation == "Subtract": | |
| result = num1 - num2 - num3 | |
| elif operation == "Multiply": | |
| result = num1 * num2 * num3 | |
| elif operation == "Divide": | |
| if num2 != 0 and num3 != 0: | |
| result = num1 / num2 / num3 | |
| else: | |
| result = "Cannot divide by zero" | |
| elif operation == "Modulus": | |
| if num2 != 0 and num3 != 0: | |
| result = num1 % num2 % num3 | |
| else: | |
| result = "Cannot perform modulus with zero" | |
| elif operation == "Exponentiation": | |
| base = st.number_input("Enter the base", value=2.0) | |
| exponent = st.number_input("Enter the exponent", value=2.0) | |
| result = base ** exponent | |
| elif operation == "Average": | |
| result = (num1 + num2 + num3) / 3 | |
| # Display result | |
| if result is not None: | |
| st.success(f"Result: {result}") | |
| if __name__ == "__main__": | |
| main() | |