coder_hangout / app.py
nightprogrammer's picture
Update app.py
3f9c2ab verified
Raw History Blame Contribute Delete
5.87 kB
import streamlit as st
import math
import time
# Inject custom CSS for the theme and hover effect
st.markdown(
"""
<style>
body {
background: linear-gradient(to right, #5e03fc, #2575fc); /* Purple-blue gradient */
color: white;
}
div[data-testid="stSidebar"] {
background: #5e03fc; /* Sidebar background */
}
div[data-testid="stMarkdownContainer"] h1, div[data-testid="stMarkdownContainer"] h2,
div[data-testid="stMarkdownContainer"] h3 {
color: #ffffff; /* Title color */
}
button {
background-color: #5e03fc !important; /* Button background */
color: white !important; /* Button text color */
border-radius: 5px !important;
}
button:hover {
background-color: #5e03fc !important; /* Hover color */
color: #e0e0ff !important; /* Slightly lighter hover text for effect */
}
div[data-testid="stMarkdownContainer"] p {
font-family: 'Trebuchet MS', sans-serif; /* Text style */
}
</style>
""",
unsafe_allow_html=True,
)
# Title with updated theme
st.title("๐Ÿš€ Advanced Night Calculator")
# Animation for menu reveal
with st.expander("๐ŸŽ›๏ธ Open the Menu (Click Me!)"):
st.markdown(
"""
<style>
@keyframes fadeIn {
from {opacity: 0;}
to {opacity: 1;}
}
div[data-testid="stMarkdownContainer"] {
animation: fadeIn 1s ease-in-out;
}
</style>
""",
unsafe_allow_html=True,
)
# Menu options with animated reveal
operation = st.selectbox(
"Choose an operation:",
[
"โž• Addition", "โž– Subtraction", "โœ–๏ธ Multiplication", "โž— Division",
"๐Ÿ”ข Exponentiation", "๐ŸŒŸ Square Root", "๐Ÿ“ Logarithm", "๐Ÿ’ก Factorial",
"๐ŸŒ Trigonometry (sin, cos, tan)", "๐Ÿงฎ Percentage", "โž— Modulus", "๐Ÿ”„ Inverse (1/x)", "โšก Absolute Value"
]
)
# Animation function for smooth transitions
def show_animation():
placeholder = st.empty()
with placeholder:
st.info("โœจ Loading your selection...")
time.sleep(1.5) # Simulate a processing time
placeholder.empty()
# Logic for operations with input fields
if operation in ["โž• Addition", "โž– Subtraction", "โœ–๏ธ Multiplication", "โž— Division", "๐Ÿ”ข Exponentiation"]:
num1 = st.number_input("Enter the first number:", value=0.0)
num2 = st.number_input("Enter the second number:", value=0.0)
if st.button("๐Ÿ“Š Calculate"):
show_animation()
if operation == "โž• Addition":
st.success(f"Result: {num1 + num2}")
elif operation == "โž– Subtraction":
st.success(f"Result: {num1 - num2}")
elif operation == "โœ–๏ธ Multiplication":
st.success(f"Result: {num1 * num2}")
elif operation == "โž— Division":
if num2 != 0:
st.success(f"Result: {num1 / num2}")
else:
st.error("๐Ÿšซ Error: Division by zero is not allowed!")
elif operation == "๐Ÿ”ข Exponentiation":
st.success(f"Result: {math.pow(num1, num2)}")
elif operation == "๐ŸŒŸ Square Root":
num = st.number_input("Enter the number:", value=0.0)
if st.button("๐Ÿ“Š Calculate"):
show_animation()
if num >= 0:
st.success(f"Result: {math.sqrt(num)}")
else:
st.error("๐Ÿšซ Error: Cannot calculate the square root of a negative number!")
elif operation == "๐Ÿ“ Logarithm":
num = st.number_input("Enter the number (greater than 0):", value=1.0)
if st.button("๐Ÿ“Š Calculate"):
show_animation()
if num > 0:
st.success(f"Result: {math.log(num)}")
else:
st.error("๐Ÿšซ Error: Logarithm undefined for non-positive numbers!")
elif operation == "๐Ÿ’ก Factorial":
num = st.number_input("Enter a non-negative integer:", value=0, step=1, min_value=0, format="%d")
if st.button("๐Ÿ“Š Calculate"):
show_animation()
st.success(f"Result: {math.factorial(num)}")
elif operation == "๐ŸŒ Trigonometry (sin, cos, tan)":
angle = st.number_input("Enter the angle in degrees:", value=0.0)
if st.button("๐Ÿ“Š Calculate"):
show_animation()
radians = math.radians(angle)
st.write(f"Sin({angle}ยฐ): {math.sin(radians):.4f}")
st.write(f"Cos({angle}ยฐ): {math.cos(radians):.4f}")
st.write(f"Tan({angle}ยฐ): {math.tan(radians):.4f}")
elif operation == "๐Ÿงฎ Percentage":
total = st.number_input("Enter the total value:", value=1.0)
portion = st.number_input("Enter the portion value:", value=0.0)
if st.button("๐Ÿ“Š Calculate Percentage"):
show_animation()
if total != 0:
result = (portion / total) * 100
st.success(f"Result: {result}%")
else:
st.error("๐Ÿšซ Error: Total value cannot be zero!")
elif operation == "โž— Modulus":
num1 = st.number_input("Enter the first number:", value=0.0)
num2 = st.number_input("Enter the second number:", value=0.0)
if st.button("๐Ÿ“Š Calculate Modulus"):
show_animation()
if num2 != 0:
st.success(f"Result: {num1 % num2}")
else:
st.error("๐Ÿšซ Error: Modulus undefined for division by zero!")
elif operation == "๐Ÿ”„ Inverse (1/x)":
num = st.number_input("Enter the number:", value=0.0)
if st.button("๐Ÿ“Š Calculate Inverse"):
show_animation()
if num != 0:
st.success(f"Result: {1 / num}")
else:
st.error("๐Ÿšซ Error: Inverse undefined for zero!")
elif operation == "โšก Absolute Value":
num = st.number_input("Enter the number:", value=0.0)
if st.button("๐Ÿ“Š Calculate Absolute Value"):
show_animation()
st.success(f"Result: {abs(num)}")