tbaig1605's picture
Update app.py
be422ee verified
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.")