Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.
Це архівний репозитарій. Ви можете переглядати і клонувати файли, але не можете робити пуш або відкривати питання/запити.
 
 
 
 
 
 

52 рядки
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()