Basically if the chosen word is "green" and the user types "e" then I want it to show "__ ee _". But instead, it shows something like this: __ e __.
How can I fix this? Here is my code:
print("Welcome to hangman game!")
import random
words = ['act', 'air', 'age', 'bag', 'cap', 'map', 'acre', 'card', 'dish', 'wack', 'exam', 'god', 'boards', 'chair', 'count', 'facts', 'house']
word = random.choice(words)
list(word)
letters_guessed = []
wrong_letters = [""]
guesses_left = 8
win_confirm = 0
for i in word:
letters_guessed.append("_")
while guesses_left > 0:
print("\nThe word contains {} letters".format(len(word)))
print("You have {} guesses left".format(guesses_left))
print(*letters_guessed)
user = input("\nEnter a letter --> ")
if user in letters_guessed or user in wrong_letters:
print("You have already entered '{}', enter another letter!".format(user))
guesses_left += 1
if user in word:
letter = word.index(user)
letters_guessed[letter] = user
print(*letters_guessed)
win_confirm += 1
if win_confirm == len(word):
print("You won!")
print("The word was '{}' ".format(word))
break
continue
else:
guesses_left -= 1
wrong_letters.append(user)
if guesses_left <= 0:
print("You don't have any chances left :(")
print("The word was '{}' ".format(word))
If there is any fix please tell me, thanks.
Aucun commentaire:
Enregistrer un commentaire