25개 이상의 토픽을 선택하실 수 없습니다. 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.
 
 
 
 
 
 

49 lines
843 B

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