Using st.session_state to output value after user st.number_input

Hey everyone,
Having some trouble outputting the values in this setup… Appreciate any help!

with st.container():
       st.write("Calculator:")

if 'Monkey' not in st.session_state:
    st.session_state['Monkey'] = 0

if 'Fish' not in st.session_state:
    st.session_state['Fish'] = 0

if 'Dog' not in st.session_state:
    st.session_state['Dog'] = 0

if 'Cat' not in st.session_state:
    st.session_state['Cat'] = 0


st.write('Monkey:', st.session_state["Monkey"])
st.write('Fish:', st.session_state["Fish"])
st.write('Dog:', st.session_state["Dog"])
st.write('Cat:', st.session_state["Cat"])
col1, buff, col2, buff, col3, buff, col4 = st.columns([2,1,2,1,2,1,2])
with col1:
    Monkey = st.number_input("Monkey ", step=1)
with col2:
    Fish = st.number_input("Fish ", step=1)
with col3:
    Dog = st.number_input("Dog ", step=1)

with col4:
    Cat = st.number_input("Cat ", step=1)

I want the numbers in the output

Monkey:0
Fish:0
Dog:0
Cat:0

To show the values the user inputs in place of the zeros.

Streamlit forum supports code formatting.

Could you put your code inside the triple backticks.

Example:

image

The output will be this.

a = 45

The backtick is in the keyboard.

image

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.