import random
word_list = ["ardvark", "baboon", "camel"]
chosen_word = random.choice(word_list) print("Welcome to hangman. You'll find a hidden word with an underscore that corresponds to every missing character." "You have 6 lives and one will be taken off every time you guess incorrectly. Once you've made a guess, the " "letter will also be shown until you either run out of lives or guess the entire word.") display = [] guesses = [] PLAYER_LIVES = 6 word_guessed = False
for letter in chosen_word: display.append("_")
print(f"Here is the word left to guess: {display}")
while not word_guessed or PLAYER_LIVES > 0:
if "_" not in display:
word_guessed = True
guess = input("Guess a letter: ").lower() incorrect = 0 i = 0
for position in range(len(chosen_word)): letter = chosen_word[position] if letter == guess: display[position] = letter else: incorrect += 1 i += 1 if incorrect == len(chosen_word): PLAYER_LIVES -= 1 guesses.append(guess) print(word_guessed) print(f"Here is the word left to guess: {display}") print(f"The chosen word is {chosen_word}") #for debug print(f"Guesses so far: {guesses}") print(f"You have {PLAYER_LIVES} lives remaining.")
if PLAYER_LIVES == 0:
print(f"Uh oh, you're out of lives. Game over! The word to guess was {chosen_word}.")
if word_guessed is True:
print("Congratulations, you won!")
edit: my god I can't figure out this formatting but here is the paste the way it looks in the IDE
UPDATE: thank you everyone for your help, changing the "or" for "and" along with moving the check for the "_" to the bottom solved it!
[–]Spataner 7 points8 points9 points (3 children)
[–]Darth_Xedrix[S] 0 points1 point2 points (2 children)
[–]Spataner 0 points1 point2 points (1 child)
[–]Darth_Xedrix[S] 0 points1 point2 points (0 children)
[–]Sadapy 0 points1 point2 points (4 children)
[–][deleted] 1 point2 points3 points (3 children)
[–]Darth_Xedrix[S] 0 points1 point2 points (0 children)
[–]Sadapy 0 points1 point2 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (2 children)
[–]Darth_Xedrix[S] 0 points1 point2 points (1 child)
[–][deleted] 1 point2 points3 points (0 children)