# Corrigé TP 1.2 : Boucles et structures conditionnelles : LE PENDU
# nathan.lardier@ac-versailles.fr

# Question 0

mot_secret = "dembélé"
mot_revele = len(mot_secret)*['_']
erreur_max = 10
erreur = 0

# Question 1

def affiche(mot):
    for x in mot:
        print(x, end='')
    print('\n')

# Question 2

def revelation(l):
    for k in range(len(mot_revele)):
        if mot_secret[k] == l:
            mot_revele[k] = mot_secret[k]

# Question 3

def victoire():
    if '_' not in mot_revele:
       return True
    return False

# La syntaxe suivante fonctionne également (les anciens NSI l'utilisent peut-être spontanément)
#def victoire():
#    return '_' not in mot_revele

# Question 4

def jouer_une_lettre():
    global erreur
    x = input("Choisissez une lettre à jouer.\n")
    revelation(x)
    if x not in mot_secret:
        erreur += 1

# Question 5

def main():
    while not victoire() and erreur < erreur_max:
        jouer_une_lettre()
        affiche(mot_revele)
    if victoire():
        print("Vous avez gagné !")
    else:
        print("Vous avez perdu !\n La solution est "+mot_secret)

# Question 6

from unicodedata import normalize
def normaliser(s):
    return normalize('NFD', s).encode('utf8').decode('ascii', 'ignore')

def revelation(l):
    for k in range(len(mot_revele)):
        if normaliser(mot_secret[k]) == l:
            mot_revele[k] = mot_secret[k]
