I’m creating a sort of game for my students with randomized stories for each group of students using random.randint().
I’ve first created a list of short stories, and then I ask then to select (when using a radio select) what calls their attention. Depending on their choice, they are prompted with a different message.
The problem is that whenever I click on a radio option, the whole app reloads and a new random number (in this case, the “nGrupo” variable) is chosen. How can I prevent that?
import random
import time
import streamlit as st
[...]
if 'interesse' not in st.session_state or 'nGrupo' not in st.session_state or 'nCoisa' not in st.session_state:
st.session_state.interesse = ''
st.session_state.nGrupo = ''
st.session_state.nCoisa = ''
st.session_state.nGrupo = random.randint(0,7)
st.session_state.nCoisa = random.randint(0,6)
st.title('Descobrindo a Genética')
st.write('Você e seu grupo são ' + grupo1[st.session_state.nGrupo] +'\n')
time.sleep(1)
st.session_state.interesse=st.radio(
"O que chama mais a atenção de vocês?",
['As maçãs dos pomares','Os milharais','Os jardins','As moscas da cozinha','As formigas no chão','O mofo das paredes','Os animais do campo'],
)
if st.session_state.interesse == 'As maçãs dos pomares':
st.write('É possível encontrar maçãs vermelhas e maçãs verdes por todo o pomar. ')
elif st.session_state.interesse == 'Os milharais':
st.write('É possível encontrar grãos de milho pequeninos e grãos grandes e arredondados por todo o milharal. ')
else:
st.write('Você escolheu outra coisa')