calculator_test / app.py
tnk2025's picture
Update app.py
72906a1 verified
import streamlit as st
st.title("Simple Calculator")
st.write("This calculator performs basic arithmetic operations.")
# Input fields for the numbers
num1 = st.number_input("Enter 1st number:", value=0.0)
num2 = st.number_input("Enter 2nd number:", value=0.0)
# Operation selection
operation = st.selectbox(
"Select operation:",("Addition", "Substraction", "Multiplication", "Division", "Exponentiation")
)
# Calculate button
if st.button("Calculate"):
if operation == "Addition":
result = num1 + num2
st.success(f"{num1} - {num2} = {result}")
elif operation == "Substraction":
result = num1 - num2
st.success(f"{num1} - {num2} = {result}")
elif operation == "Multiplication":
result = num1 * num2
st.success(f"{num1} * {num2} = {result}")
elif operation == "Division":
if num2 == 0:
st.error("Error: Division by zero!")
else:
result = num1 / num2
st.success(f"{num1} / {num2} = {result}")
elif operation == "Exponentiation":
result = num1 ** num2
st.success(f"{num1} ^ {num2} = {result}")
# Add a divider and display instructions
st.divider()
# Additional calculator history section
st.subheader("History")
st.write("Your calculation history will appear here.")
# How to use section
st.subheader("How to Use")
st.write("""
1. Enter the 1st Number
2. Enter the 2nd Number
3. Select the operation from the dropdown
4. Click the 'Calculate' button
""")
# Footer
st.divider()
st.caption("Simple Calculator App built with Streamlit")