Spaces:
Sleeping
Sleeping
| import streamlit as st | |
| # Page config | |
| st.set_page_config(page_title="Simple Calculator", page_icon="🧮", layout="centered") | |
| # Title and subtitle | |
| st.title("🧮 Simple Streamlit Calculator") | |
| st.markdown("Perform basic math operations with ease.") | |
| # Divider | |
| st.markdown("---") | |
| # Input fields | |
| col1, col2 = st.columns(2) | |
| with col1: | |
| num1 = st.number_input("🔢 Enter the first number", format="%.2f") | |
| with col2: | |
| num2 = st.number_input("🔢 Enter the second number", format="%.2f") | |
| # Operation selection | |
| operation = st.selectbox("➕ Choose an operation", ["Addition", "Subtraction", "Multiplication", "Division"]) | |
| # Button and result | |
| if st.button("💡 Calculate"): | |
| st.markdown("### 🧾 Result") | |
| try: | |
| if operation == "Addition": | |
| result = num1 + num2 | |
| elif operation == "Subtraction": | |
| result = num1 - num2 | |
| elif operation == "Multiplication": | |
| result = num1 * num2 | |
| elif operation == "Division": | |
| if num2 == 0: | |
| st.error("🚫 Cannot divide by zero.") | |
| result = None | |
| else: | |
| result = num1 / num2 | |
| if result is not None: | |
| st.success(f"✅ The result is: `{result}`") | |
| except Exception as e: | |
| st.error(f"❌ An error occurred: {e}") | |
| # Footer | |
| st.markdown("---") | |
| st.caption("Created with ❤️ using BilalCode") | |