Spaces:
Sleeping
Sleeping
File size: 838 Bytes
dabb2cb |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
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}")
|