Spaces:
Sleeping
Sleeping
File size: 5,868 Bytes
8873371 0e1f4eb 8873371 3f9c2ab 987710a 82bf5c9 987710a 82bf5c9 987710a 82bf5c9 987710a 3f9c2ab 987710a 3f9c2ab c06e644 54b46fc c06e644 8873371 c06e644 987710a 0e1f4eb 987710a 0e1f4eb 987710a 0e1f4eb 987710a 0e1f4eb 987710a 0e1f4eb 987710a 0e1f4eb 54b46fc 987710a 54b46fc 987710a 54b46fc 987710a 54b46fc 987710a 54b46fc | 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 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 | 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)}") |