|
|
import streamlit as st |
|
|
|
|
|
|
|
|
st.title("🧮 Simple Calculator") |
|
|
|
|
|
|
|
|
num1 = st.number_input("Enter the first number:", format="%.2f") |
|
|
num2 = st.number_input("Enter the second number:", format="%.2f") |
|
|
|
|
|
|
|
|
operation = st.selectbox( |
|
|
"Select operation:", |
|
|
("Add", "Subtract", "Multiply", "Divide") |
|
|
) |
|
|
|
|
|
|
|
|
if st.button("Calculate"): |
|
|
if operation == "Add": |
|
|
result = num1 + num2 |
|
|
st.success(f"Result: {result:.2f}") |
|
|
elif operation == "Subtract": |
|
|
result = num1 - num2 |
|
|
st.success(f"Result: {result:.2f}") |
|
|
elif operation == "Multiply": |
|
|
result = num1 * num2 |
|
|
st.success(f"Result: {result:.2f}") |
|
|
elif operation == "Divide": |
|
|
if num2 == 0: |
|
|
st.error("❌ Cannot divide by zero.") |
|
|
else: |
|
|
result = num1 / num2 |
|
|
st.success(f"Result: {result:.2f}") |