import streamlit as st import math # Custom styling using Markdown st.markdown( """ """, unsafe_allow_html=True ) # Title st.markdown("

Advanced Calculator

", unsafe_allow_html=True) # Input fields num1 = st.number_input("Enter First Number", format="%.4f") num2 = st.number_input("Enter Second Number", format="%.4f") # Operation choices operations = [ "Add", "Subtract", "Multiply", "Divide", "Power", "Modulus", "Square Root (1st Number)", "Logarithm (1st Number)" ] operation = st.selectbox("Choose Operation", operations) # Calculate button if st.button("Calculate"): try: if operation == "Add": result = num1 + num2 elif operation == "Subtract": result = num1 - num2 elif operation == "Multiply": result = num1 * num2 elif operation == "Divide": if num2 != 0: result = num1 / num2 else: st.error("❌ Cannot divide by zero!") result = None elif operation == "Power": result = num1 ** num2 elif operation == "Modulus": result = num1 % num2 elif operation == "Square Root (1st Number)": if num1 >= 0: result = math.sqrt(num1) else: st.error("❌ Cannot take square root of a negative number!") result = None elif operation == "Logarithm (1st Number)": if num1 > 0: result = math.log(num1) else: st.error("❌ Logarithm undefined for 0 or negative numbers!") result = None if result is not None: st.success(f"✅ Result: {result:.4f}") except Exception as e: st.error(f"⚠️ Error: {str(e)}")