๐Streamlit Application #1
Goal
What is Streamlit?

Getting Started
How our App Looks

Python Code using Streamlit
Last updated


Last updated
# Streamlit Python Application
# Dependency Imports
import streamlit as st
# Application
st.title("Calculator App")
# Select an operation
choice = st.selectbox(
label="Choose an operation.",
options=["Add", "Subtract", "Multiply", "Divide"],
index=None,
placeholder="Choose one of the options"
)
# Provide two operands for our operations
# Only if the user has selected an operation
# we could have also wrote: if choice is not None:
if choice:
num1 = st.number_input(
label="Enter a value.",
value=0.0,
key="operand1"
)
num2 = st.number_input(
label="Enter a value.",
value=0.0,
key="operand2"
)
result = 0 # initialize our answer container
# Displaying our answer
st.write("The calculation:")
if choice == "Add":
result = num1 + num2
st.write(f"{num1} + {num2} = {result}")
elif choice == "Subtract":
result = num1 - num2
st.write(f"{num1} - {num2} = {result}")
elif choice == "Multiply":
result = num1 * num2
st.write(f"{num1} * {num2} = {result}")
elif choice == "Divide":
if num2 == 0:
st.write("Invalid denominator, cannot divide by zero.")
else:
result = num1 / num2
st.write(f"{num1} / {num2} = {result}")