Spaces:
Sleeping
Sleeping
File size: 1,737 Bytes
c87ffd4 e18f3b2 c87ffd4 e18f3b2 |
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.title("🧮 Simple Calculator")
# Input fields
num1 = st.number_input("Enter first number", value=0.0)
num2 = st.number_input("Enter second number", value=0.0)
# Operation selection
operation = st.selectbox(
"Select Operation",
[
"Addition (+)",
"Subtraction (-)",
"Multiplication (×)",
"Division (÷)",
"Modulus (%)",
"Exponentiation (^)",
"Floor Division (//)",
"Average"
]
)
# 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: Cannot divide by zero")
elif operation == "Modulus (%)":
if num2 != 0:
result = num1 % num2
st.success(f"Result: {result}")
else:
st.error("Error: Cannot perform modulus with zero")
elif operation == "Exponentiation (^)":
result = num1 ** num2
st.success(f"Result: {result}")
elif operation == "Floor Division (//)":
if num2 != 0:
result = num1 // num2
st.success(f"Result: {result}")
else:
st.error("Error: Cannot perform floor division by zero")
elif operation == "Average":
result = (num1 + num2) / 2
st.success(f"Result: {result}")
|