Spaces:
Sleeping
Sleeping
import streamlit as st | |
# Title of the app | |
st.title("Simple Calculator Application") | |
# Subheader | |
st.subheader("Select an operation and enter two numbers:") | |
# Create a dropdown for selecting an operation | |
operation = st.selectbox( | |
"Select an operation:", | |
["Addition", "Subtraction", "Multiplication", "Division"] | |
) | |
# Input fields for numbers | |
num1 = st.number_input("Enter the first number:", format="%.2f") | |
num2 = st.number_input("Enter the second number:", format="%.2f") | |
# Calculate button | |
if st.button("Calculate"): | |
# Check if the second number is zero when dividing | |
if operation == "Division" and num2 == 0: | |
st.error("Error: Division by zero is not allowed!") | |
else: | |
# Perform the calculation based on the selected operation | |
if operation == "Addition": | |
result = num1 + num2 | |
st.write(f"The result of {num1:.2f} + {num2:.2f} is: {result:.2f}") | |
elif operation == "Subtraction": | |
result = num1 - num2 | |
st.write(f"The result of {num1:.2f} - {num2:.2f} is: {result:.2f}") | |
elif operation == "Multiplication": | |
result = num1 * num2 | |
st.write(f"The result of {num1:.2f} * {num2:.2f} is: {result:.2f}") | |
elif operation == "Division": | |
result = num1 / num2 | |
st.write(f"The result of {num1:.2f} / {num2:.2f} is: {result:.2f}") | |