From 660d4e582f671cd4d99d6ba421a575b8b34c2e3b Mon Sep 17 00:00:00 2001 From: Dimitri Merejkowsky Date: Sat, 28 Sep 2019 19:00:37 +0200 Subject: [PATCH] Version de pendu.py finale --- saison-2/sources/pendu.py | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/saison-2/sources/pendu.py b/saison-2/sources/pendu.py index bec5bff..917db7f 100644 --- a/saison-2/sources/pendu.py +++ b/saison-2/sources/pendu.py @@ -11,10 +11,41 @@ def choisir_mot_au_hasard(): return mots[index] - def main(): mot = choisir_mot_au_hasard() - print(mot) + # pour debuggage + # print(mot) + tentatives = [] + while True: + afficher_indice(mot, tentatives) + lettre = demander_lettre() + tentatives += [lettre] + if a_gagné(mot, tentatives): + print("Gagné") + print(mot) + break + + +def a_gagné(mot, tentatives): + for c in mot: + if c not in tentatives: + return False + return True + + +def demander_lettre(): + print("entrer une lettre") + lettre = input() + return lettre + + +def afficher_indice(mot, tentatives): + for c in mot: + if c in tentatives: + print(c, end="") + else: + print("_", end="") + print() main()