coders_hangout / app.py
nightprogrammer's picture
Create app.py
279a8c9 verified
Raw History Blame Contribute Delete
1.8 kB
import streamlit as st
import math
# Title of the web app
st.title("✨ Enhanced Calculator ✨")
# Dropdown menu for operation selection with emojis
operation = st.selectbox(
"Select an operation:",
["βž• Addition", "βž– Subtraction", "βœ–οΈ Multiplication", "βž— Division", "πŸ”’ Exponentiation", "🌟 Square Root"]
)
# Number inputs based on the selected operation
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"):
if operation == "βž• Addition":
result = num1 + num2
st.success(f"βœ… Result: {result}")
elif operation == "βž– Subtraction":
result = num1 - num2
st.success(f"βœ… Result: {result}")
elif operation == "βœ–οΈ Multiplication":
result = num1 * num2
st.success(f"βœ… Result: {result}")
elif operation == "βž— Division":
if num2 != 0:
result = num1 / num2
st.success(f"βœ… Result: {result}")
else:
st.error("🚫 Error: Division by zero is not allowed!")
elif operation == "πŸ”’ Exponentiation":
result = math.pow(num1, num2)
st.success(f"βœ… Result: {result}")
elif operation == "🌟 Square Root":
num = st.number_input("Enter the number: 🏷️", value=0.0)
if st.button("πŸ“Š Calculate"):
if num >= 0:
result = math.sqrt(num)
st.success(f"βœ… Result: {result}")
else:
st.error("🚫 Error: Cannot calculate the square root of a negative number!")