您不能選擇超過 %s 個話題 話題必須以字母或數字為開頭,可包含連接號 ('-') 且最長為 35 個字
此存儲庫已封存,您能瀏覽檔案及複製此存儲庫,但不能推送、建立問題及拉取請求。

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