streamlit-calculator / src /streamlit_app.py
Zohaib366's picture
Updated the code in streamlit_app.py file.
7bdad3d
raw
history blame contribute delete
797 Bytes
import streamlit as st
st.title("Simple Calculator")
# Input numbers as text
num1 = st.text_input("Enter first number:", "0")
num2 = st.text_input("Enter second number:", "0")
# Convert input to integers
try:
num1 = int(num1)
num2 = int(num2)
except ValueError:
st.error("Please enter valid integers.")
# Operation selection
operation = st.radio("Select operation:", ("Add", "Subtract", "Multiply", "Divide"))
# Calculate result
if st.button("Calculate"):
if operation == "Add":
result = num1 + num2
elif operation == "Subtract":
result = num1 - num2
elif operation == "Multiply":
result = num1 * num2
elif operation == "Divide":
result = num1 / num2 if num2 != 0 else "Error: Division by zero!"
st.success(f"Result: {result}")