Spaces:
Build error
Build error
File size: 1,796 Bytes
279a8c9 | 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 | 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!") |