RanaZaeem12's picture
Update app.py
3c20eed verified
import streamlit as st # Make sure this is at the very top
st.set_page_config(page_title="🧮 Simple Calculator App", page_icon="🧮")
st.title("🧮 Simple Calculator App")
# Input fields
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 an operation", (
"Addition",
"Subtraction",
"Multiplication",
"Division",
"Modulus (Remainder)",
"Exponentiation (Power)",
"Floor Division",
"Average",
"Maximum",
"Minimum"
))
# Perform calculation
if st.button("Calculate"):
if operation == "Addition":
result = num1 + num2
st.success(f"The result of addition is: {result}")
elif operation == "Subtraction":
result = num1 - num2
st.success(f"The result of subtraction is: {result}")
elif operation == "Multiplication":
result = num1 * num2
st.success(f"The result of multiplication is: {result}")
elif operation == "Division":
if num2 != 0:
result = num1 / num2
st.success(f"The result of division is: {result}")
else:
st.error("Division by zero is not allowed!")
elif operation == "Modulus (Remainder)":
if num2 != 0:
result = num1 % num2
st.success(f"The result of modulus is: {result}")
else:
st.error("Modulus by zero is not allowed!")
elif operation == "Exponentiation (Power)":
result = num1 ** num2
st.success(f"The result of {num1} ^ {num2} is: {result}")
elif operation == "Floor Division":
if num2 != 0:
result = num1 // num2
st.success(f"The result of floor division is: {result}")
else:
st.error("Floor division by zero is not allowed!")
elif operation == "Average":
result = (num1 + num2) / 2
st.success(f"The average of the two numbers is: {result}")
elif operation == "Maximum":
result = max(num1, num2)
st.success(f"The maximum of the two numbers is: {result}")
elif operation == "Minimum":
result = min(num1, num2)
st.success(f"The minimum of the two numbers is: {result}")