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!")