I'm coding a simple hangman game, but when I subtract 1 from lives, 1 is subtracted no matter the condition. How would I code this in a way that 1 is subtracted only if guess is not equal to any letter in the word?
lives = 6 < ---- starting num of lives
game_over = False
while not game_over:
guess = input("Guess a letter. ")
for pos in range(len(chosen_word)): < - - chosen word is the randomly chosen word
letter = chosen_word[pos]
if letter == guess:
display[pos] = letter
print(display)
if display.count("_") == 0:
print("Game over. ")
game_over = True
elif letter != guess: < these lines are meant to subtract a life only if
lives = lives - 1 < letter is not equal to guess, but they actually
print(f"Lives: {lives}") < subtract no matter what. How do I fix this?
elif lives == 0:
game_over = True
print("Game over. ")