File size: 1,931 Bytes
00604b3
520d768
00604b3
520d768
 
00604b3
520d768
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
00604b3
520d768
 
 
00604b3
520d768
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st
import math

# Set page config
st.set_page_config(page_title="Advanced Calculator", page_icon="🧮", layout="centered")

# Custom CSS for better UI
st.markdown("""
    <style>
    .main {
        background-color: #f0f2f6;
        padding: 20px;
        border-radius: 15px;
        box-shadow: 2px 2px 10px rgba(0,0,0,0.1);
    }
    .title {
        color: #4CAF50;
        text-align: center;
    }
    .result {
        background-color: #dff0d8;
        padding: 10px;
        border-radius: 10px;
        text-align: center;
        font-size: 20px;
    }
    </style>
""", unsafe_allow_html=True)

# Main Container
with st.container():
    st.markdown("<h1 class='title'>🧮 Advanced Calculator</h1>", unsafe_allow_html=True)
    
    num1 = st.number_input("Enter first number", value=0.0)
    num2 = st.number_input("Enter second number", value=0.0)

    operation = st.selectbox(
        "Select operation",
        ["Addition (+)", "Subtraction (-)", "Multiplication (×)", "Division (÷)", 
         "Modulus (%)", "Exponent (xʸ)", "Square Root (√ First Number)"]
    )

    if st.button("Calculate"):
        if operation == "Addition (+)":
            result = num1 + num2
        elif operation == "Subtraction (-)":
            result = num1 - num2
        elif operation == "Multiplication (×)":
            result = num1 * num2
        elif operation == "Division (÷)":
            result = num1 / num2 if num2 != 0 else "Error: Division by zero"
        elif operation == "Modulus (%)":
            result = num1 % num2 if num2 != 0 else "Error: Division by zero"
        elif operation == "Exponent (xʸ)":
            result = num1 ** num2
        elif operation == "Square Root (√ First Number)":
            result = math.sqrt(num1) if num1 >= 0 else "Error: Negative number"
        
        st.markdown(f"<div class='result'>Result: {result}</div>", unsafe_allow_html=True)