NazishHasan's picture
Update app.py
ac1a2a5 verified
Raw
History Blame Contribute Delete
1.35 kB
# app.py
import streamlit as st
st.title("🧮 Simple Calculator App")
st.write("Select an operation and enter two numbers:")
# Input fields
num1 = st.number_input("Enter the first number:")
num2 = st.number_input("Enter the second number:")
operation = st.selectbox(
"Choose an operation:",
("Addition (+)", "Subtraction (-)", "Multiplication (*)", "Division (/)",
"Exponentiation (^)", "Modulus (%)", "Floor Division (//)")
)
result = None
# Calculation logic
if st.button("Calculate"):
if operation == "Addition (+)":
result = num1 + num2
elif operation == "Subtraction (-)":
result = num1 - num2
elif operation == "Multiplication (*)":
result = num1 * num2
elif operation == "Division (/)":
if num2 != 0:
result = num1 / num2
else:
st.error("Cannot divide by zero!")
elif operation == "Exponentiation (^)":
result = num1 ** num2
elif operation == "Modulus (%)":
if num2 != 0:
result = num1 % num2
else:
st.error("Cannot perform modulus by zero!")
elif operation == "Floor Division (//)":
if num2 != 0:
result = num1 // num2
else:
st.error("Cannot perform floor division by zero!")
if result is not None:
st.success(f"Result: {result}")