I have 3 lists: type_1,type_2, type_3
I want to create a yes/no questionnaire of 10 questions. For each question if the answer is yes I want to add 1 to one of the lists above(let’s say type_1) and at the end I want to show the name of the list which has the highest sum.
I can’t add 1 to let’s say type_1 list after the first question.
What I’ve done is :
answers = [‘yes’, ‘no’]
q_1 = st.radio(‘1.Are you a discipline person?’, answers)
if q_1 == ‘yes’:
type_1.append(1)
else:
type_1.append(0)
import streamlit as st
type_1 = []
ANSWERS = ['yes', 'no']
questions_type_1 = [
"1. Are you a disciplined person?",
"2. Do you often follow a daily routine?",
"3. Are you detail-oriented in your work?"
]
for question in questions_type_1:
response = st.radio(
label=question,
options=ANSWERS,
key=question, # here
horizontal=True
)
type_1.append(1 if response == 'yes' else 0)
st.write(type_1)
Thanks for stopping by! We use cookies to help us understand how you interact with our website.
By clicking “Accept all”, you consent to our use of cookies. For more information, please see our privacy policy.
Cookie settings
Strictly necessary cookies
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.
Performance cookies
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us understand how visitors move around the site and which pages are most frequently visited.
Functional cookies
These cookies are used to record your choices and settings, maintain your preferences over time and recognize you when you return to our website. These cookies help us to personalize our content for you and remember your preferences.
Targeting cookies
These cookies may be deployed to our site by our advertising partners to build a profile of your interest and provide you with content that is relevant to you, including showing you relevant ads on other websites.