Spaces:
Running
Running
import streamlit as st | |
# Title | |
st.title("🧮 Simple Calculator") | |
# User Inputs | |
st.write("Enter two numbers and choose an operation:") | |
num1 = st.number_input("Enter first number", format="%f") | |
num2 = st.number_input("Enter second number", format="%f") | |
operation = st.selectbox("Choose operation", ("Add", "Subtract", "Multiply", "Divide")) | |
# Button | |
if st.button("Calculate"): | |
if operation == "Add": | |
result = num1 + num2 | |
st.success(f"Result: {result}") | |
elif operation == "Subtract": | |
result = num1 - num2 | |
st.success(f"Result: {result}") | |
elif operation == "Multiply": | |
result = num1 * num2 | |
st.success(f"Result: {result}") | |
elif operation == "Divide": | |
if num2 != 0: | |
result = num1 / num2 | |
st.success(f"Result: {result}") | |
else: | |
st.error("Division by zero is not allowed.") | |