Im testing new things and I landed on python... As first code i found the classic hangman game.
I followed a tutorial that shows how to do it step by step but when it comes to wordlist I've got lost... So far I've been retrieving the words from a variable "_WORDS" which it has some strings as properties. I have now a "words.txt" file from which I want to get the words instead of the variable _WORDS = ("word1", "word2", "etc"). I found some examples but I cant hack it... some inspiration? This is my code...
_WORDS = open("words.txt", 'r')
_IFYOUWIN = ("you won!")
def __init__(self):
self._word = choice(self._WORDS)
self._so_far = "-" * len(self._word)
self._used = []
self._wrong_answers = 0
def play(self):
self._reset_game()
self._start_game()
while self._wrong_answers < len(self._HANGMAN) and self._so_far != self._word:
self._print_current_progress()
guess = self._user_guess()
self._check_answer(guess)
I tried importing "os" like this:
import os
_WORDS = os.path.expanduser("~/Desktop/pythontlearn/words.txt")
but no luck.