File size: 1,391 Bytes
1c93d6d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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")