File size: 1,108 Bytes
0d1dc54
b515024
 
 
 
4c30987
0a8d595
e7ff442
3264e74
 
 
2f49472
6b34d8c
3264e74
 
 
 
 
 
 
 
 
 
 
 
32884fe
3264e74
4c30987
3264e74
4c30987
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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()