You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.
 
 
 
 
 
 

52 lines
971 B

  1. import random
  2. def choisir_mot_au_hasard():
  3. fichier = open("mots.txt")
  4. contenu = fichier.read()
  5. fichier.close()
  6. mots = contenu.splitlines()
  7. n = len(mots)
  8. index = random.randint(0, n - 1)
  9. return mots[index]
  10. def main():
  11. mot = choisir_mot_au_hasard()
  12. # pour debuggage
  13. # print(mot)
  14. tentatives = []
  15. while True:
  16. afficher_indice(mot, tentatives)
  17. lettre = demander_lettre()
  18. tentatives += [lettre]
  19. if a_gagné(mot, tentatives):
  20. print("Gagné")
  21. print(mot)
  22. break
  23. def a_gagné(mot, tentatives):
  24. for c in mot:
  25. if c not in tentatives:
  26. return False
  27. return True
  28. def demander_lettre():
  29. print("entrer une lettre")
  30. lettre = input()
  31. return lettre
  32. def afficher_indice(mot, tentatives):
  33. for c in mot:
  34. if c in tentatives:
  35. print(c, end="")
  36. else:
  37. print("_", end="")
  38. print()
  39. main()