No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
Este repositorio está archivado. Puede ver los archivos y clonarlo, pero no puede subir cambios o reportar incidencias ni pedir Pull Requests.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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()