anamjafar6's picture
Update app.py
520d768 verified
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)