Cannot delete None at the bottom

I try to prepare a questionnaire of 5 yes no questions.

The problem is after the result line at the end there are 5 lines only written as None.

The code is :slight_smile:

answers = [โ€˜Yesโ€™, โ€˜Noโ€™]

question_1 = tab_2.radio(โ€˜1.tired.โ€™, answers)

tip_1.append(1) if question_1 == โ€˜Yesโ€™ else tip_1.append(0)

question_2 = tab_2.radio(โ€˜2.dizzy.โ€™, answers)

tip_5.append(1) if question_2 == โ€˜Yesโ€™ else tip_5.append(0)

question_3 = tab_2.radio(โ€˜3.Nausea.โ€™, answers)

tip_9.append(1) if question_3 == โ€˜Yesโ€™ else tip_9.append(0)

question_4 = tab_2.radio(โ€˜4.Vomit.โ€™, answers)

tip_2.append(1) if question_4 == โ€˜Yesโ€™ else tip_2.append(0)

question_5 = tab_2.radio(โ€˜5.Headache.โ€™, answers)

tip_8.append(1) if question_5 == โ€˜Yesโ€™ else tip_8.append(0)

sum_lists = [sum(tip_1), sum(tip_2), sum(tip_3), sum(tip_4), sum(tip_5), sum(tip_6), sum(tip_7), sum(tip_8), sum(tip_9)]

max_list_index = sum_lists.index(max(sum_lists))

tab_2.write(f"Your type is tip{max_list_index + 1}")

In the website, after the result line there are 5 lines of None

None

None

None

None

I couldnโ€™t get rid of them.

I have three tabs and I have these five None line in each of the tabs.

Could you please help me?

Try turning off Streamlit Magic. Or terminate the if/else constructs with a semi-colon.

1 Like

Hi @Yusuf_Gungoray

Agreeing with @asehmi that the if/else formatting may be the cause of the problem:

Try refactoring the code in the following structure:

if question_1 == โ€˜Yesโ€™:
   tip_1.append(1)
else:
   tip_1.append(0)

Thank you so much. It worked

Thank you so much for the code. It was very helpful.

1 Like

Glad to hear that it works now.

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