File size: 2,175 Bytes
3441337
09bc469
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3441337
 
09bc469
3441337
 
09bc469
 
 
 
 
 
 
 
3441337
09bc469
3441337
09bc469
3441337
09bc469
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st
import math

# Custom styling using Markdown
st.markdown(
    """
    <style>
    .main {
        background-color: #f0f4f8;
    }
    .stButton>button {
        color: white;
        background-color: #4CAF50;
        font-size: 16px;
        border-radius: 10px;
        padding: 10px 24px;
    }
    .stSelectbox, .stNumberInput {
        background-color: #ffffff;
    }
    </style>
    """,
    unsafe_allow_html=True
)

# Title
st.markdown("<h1 style='color: #3366cc; text-align: center;'>Advanced Calculator</h1>", unsafe_allow_html=True)

# Input fields
num1 = st.number_input("Enter First Number", format="%.4f")
num2 = st.number_input("Enter Second Number", format="%.4f")

# Operation choices
operations = [
    "Add", "Subtract", "Multiply", "Divide",
    "Power", "Modulus", "Square Root (1st Number)", "Logarithm (1st Number)"
]

operation = st.selectbox("Choose Operation", operations)

# Calculate button
if st.button("Calculate"):
    try:
        if operation == "Add":
            result = num1 + num2
        elif operation == "Subtract":
            result = num1 - num2
        elif operation == "Multiply":
            result = num1 * num2
        elif operation == "Divide":
            if num2 != 0:
                result = num1 / num2
            else:
                st.error("❌ Cannot divide by zero!")
                result = None
        elif operation == "Power":
            result = num1 ** num2
        elif operation == "Modulus":
            result = num1 % num2
        elif operation == "Square Root (1st Number)":
            if num1 >= 0:
                result = math.sqrt(num1)
            else:
                st.error("❌ Cannot take square root of a negative number!")
                result = None
        elif operation == "Logarithm (1st Number)":
            if num1 > 0:
                result = math.log(num1)
            else:
                st.error("❌ Logarithm undefined for 0 or negative numbers!")
                result = None

        if result is not None:
            st.success(f"✅ Result: {result:.4f}")

    except Exception as e:
        st.error(f"⚠️ Error: {str(e)}")