import streamlit as st import math import time # Inject custom CSS for the theme and hover effect st.markdown( """ """, 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( """ """, 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)}")