Spaces:
Sleeping
Sleeping
import random | |
import streamlit as st | |
st.title("Benvingut al joc Endevina el número secret.") | |
st.header("Aconsegueix-ho amb el nombre mínim d'intent") | |
if 'ja tinc pensat el numero' not in st.session_state: | |
secret = random.randint(1,101) | |
st.session_state['ja tinc pensat el numero'] = True | |
st.session_state['secret'] = secret | |
st.session_state['intents'] = 0 | |
secret = st.session_state['secret'] | |
st.write(f"Número secret: {secret} (no li diguis a ningú)") | |
jugador = st.slider('Escull un valor', 0, 100) | |
if not jugador: | |
st.stop() | |
elif jugador > secret: | |
st.write("Massa alt! Torna-ho a provar") | |
st.session_state['intents'] = st.session_state['intents'] + 1 | |
st.stop() | |
elif jugador < secret: | |
st.write("Massa baix! Torna-ho a provar") | |
st.session_state['intents'] = st.session_state['intents'] + 1 | |
st.stop() | |
elif jugador == secret: | |
encertat = True | |
intents = st.session_state['intents'] | |
st.write(f"Has necessitat {intents} intents d'endevinar el número secret! GAME OVER") | |
del st.session_state['ja tinc pensat el numero'] | |
st.stop() | |