Spaces:
Sleeping
Sleeping
import streamlit as st | |
st.title("Simple Calculator") | |
# Input fields | |
num1 = st.number_input("Enter first number", format="%.2f") | |
operation = st.selectbox("Select operation", ["+", "-", "*", "/"]) | |
num2 = st.number_input("Enter second number", format="%.2f") | |
# Perform calculation | |
result = None | |
error = None | |
if st.button("Calculate"): | |
try: | |
if operation == "+": | |
result = num1 + num2 | |
elif operation == "-": | |
result = num1 - num2 | |
elif operation == "*": | |
result = num1 * num2 | |
elif operation == "/": | |
if num2 != 0: | |
result = num1 / num2 | |
else: | |
error = "Cannot divide by zero" | |
except Exception as e: | |
error = str(e) | |
if error: | |
st.error(error) | |
else: | |
st.success(f"Result: {result:.2f}") | |