Why does the variable 'user_style' not pass the if clause? Also, how do i make the program wait until the user enters a value in the text_input field?

  1. Here is the code snippet in question:
    st.write('The style for today will be ', style, '. If you would like to change this, enter it in the text box below.')
    user_style = st.text_input('Style','Casual')
    if(user_style != 'Casual' or user_style != 'Classy-casual' or user_style != 'Classy'):
        print('The value you entered is not an option. Style will remain ' + style)
    else:
        st.write('Style changed to ', user_style)
        style = user_style

By debugging I find that user_style does get the default value of ‘Casual’, but the if statement evaluates true.

  1. How would I go about making the program wait until the user actually inputs a value in the text_input field? I ask this because some choices are made based on style and I want the user to be able to make their choice before the program continues.

Suggestion:
You could replace your current if statement with the following line:

if user_style in [ ‘Casual’, ‘Classy-casual’, ‘Classy’]:

Solution: Add another if statement before your current if statement as below:

If user_style != ‘’:

and indent the rest of the lines as needed.

Additional reading from Streamlit docs: st.stop()

Also, remove ‘Casual’ from st.text_input line

Thank you for your feedback and solutions! I found out that if i do

if(user_style == 'Casual' or user_style == 'Classy-casual' or user_style == 'Classy')

instead, the if statement evaluates correctly. Just adding this for posterity sake