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.
 
 
 
 
 
 

51 lines
1005 B

  1. import random
  2. def lire_mots():
  3. fichier = open("mots.txt")
  4. contenu = fichier.read()
  5. fichier.close()
  6. mots = contenu.splitlines()
  7. return mots
  8. def choisir_mot_au_hasard(mots):
  9. taille = len(mots)
  10. index = random.randint(0, taille)
  11. return mots[0]
  12. def jouer():
  13. mots = lire_mots()
  14. mot = choisir_mot_au_hasard(mots)
  15. # pour débugger, il faudra enlever cet
  16. # appel à print une fois le code terminé
  17. print("Le mot à deviner est", mot)
  18. tentatives = []
  19. while True:
  20. afficher_indice(mot, tentatives)
  21. lettre = demander_lettre()
  22. if lettre not in tentatives:
  23. tentatives += [lettre]
  24. if a_gagné(mot, tentatives):
  25. print(mot)
  26. print("Gagné")
  27. break
  28. def a_gagné(mot, tentatives):
  29. return False
  30. def demander_lettre():
  31. print("entrer une lettre")
  32. lettre = input()
  33. return lettre
  34. def afficher_indice(mot, tentatives):
  35. print("tentatives", tentatives)
  36. jouer()