File size: 1,786 Bytes
0c2e410
 
 
 
 
e9bfd9c
0c2e410
 
 
 
 
 
e9bfd9c
 
 
 
 
 
 
 
 
 
 
0c2e410
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e9bfd9c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
be422ee
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import streamlit as st

st.set_page_config(page_title="Simple Calculator", page_icon="🧮")

st.title("🧮 Simple Calculator")
st.write("This app performs basic arithmetic operations: +, −, ×, ÷, ^, %, //")

# Input numbers
num1 = st.number_input("Enter the first number", format="%.2f")
num2 = st.number_input("Enter the second number", format="%.2f")

# Operation selection
operation = st.selectbox(
    "Choose operation", (
        "Addition (+)",
        "Subtraction (−)",
        "Multiplication (×)",
        "Division (÷)",
        "Exponentiation (^)",
        "Modulus (%)",
        "Floor Division (//)"
    )
)

# Calculate result
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 = num1 ** num2
        st.success(f"Result: {result}")
    elif operation == "Modulus (%)":
        if num2 != 0:
            result = num1 % num2
            st.success(f"Result: {result}")
        else:
            st.error("Error: Modulus by zero is not allowed.")
    elif operation == "Floor Division (//)":
        if num2 != 0:
            result = num1 // num2
            st.success(f"Result: {result}")
        else:
            st.error("Error: Floor division by zero is not allowed.")