File size: 2,722 Bytes
75aeb5c
 
e7886df
206d23c
 
 
e7886df
206d23c
e7886df
 
206d23c
 
e7886df
206d23c
e7886df
 
 
 
 
 
 
 
 
 
 
 
206d23c
e7886df
 
 
 
 
 
 
 
 
 
 
 
 
 
206d23c
 
 
e7886df
206d23c
 
 
 
 
 
75aeb5c
206d23c
e7886df
75aeb5c
e7886df
 
 
 
75aeb5c
191936c
 
16e1477
191936c
16e1477
75aeb5c
 
 
 
16e1477
75aeb5c
16e1477
75aeb5c
16e1477
75aeb5c
16e1477
 
75aeb5c
 
16e1477
 
 
 
 
 
fc86e28
 
 
16e1477
 
75aeb5c
 
 
 
 
 
206d23c
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
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()