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
897 B

  1. import random
  2. def read_words():
  3. stream = open("noms.txt")
  4. words = stream.read().splitlines()
  5. stream.close()
  6. return words
  7. def choose_word(words):
  8. n = len(words)
  9. index = random.randint(0, n-1)
  10. return words[index]
  11. def has_won(word, letters):
  12. for letter in word:
  13. if letter not in letters:
  14. return False
  15. return True
  16. def display_hint(word, letters):
  17. for letter in word:
  18. if letter in letters:
  19. print(letter, end="")
  20. else:
  21. print("_", end="")
  22. print("")
  23. def main():
  24. words = read_words()
  25. word = choose_word(words)
  26. print(word)
  27. letters = set()
  28. display_hint(word, letters)
  29. while True:
  30. new_letter = input()
  31. letters.add(new_letter)
  32. display_hint(word, letters)
  33. if has_won(word, letters):
  34. print("Gagné")
  35. return
  36. main()