File size: 946 Bytes
d8e827d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
32
33
34
35
36
import logging

from streamlit import session_state


def guess_letter(letter: str, session: session_state) -> session_state:
    """Take a letter and evaluate if it is part of the hangman puzzle
    then updates the session object accordingly.

    Args:Chosen letter
        letter (str): Streamlit session object
        session (session_state): _description_

    Returns:
        session_state: Updated session
    """
    logger.info(f"Letter '{letter}' picked")
    if letter in session["word"]:
        session["correct_letters"].append(letter)
    else:
        session["missed_letters"].append(letter)

    hangman = "".join(
        [
            (letter if letter in session["correct_letters"] else "_")
            for letter in session["word"]
        ]
    )
    session["hangman"] = hangman
    logger.info("Session state updated")
    return session


logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__file__)