import random
# making a list with word_list
word_list = ['Lemon', 'Apple', 'Kiwi']
#picking random word
chosen_word = random.choice(word_list)
print(f'the solution is {chosen_word}.')
display = []
word_length = len(chosen_word)
for _ in range(word_length):
display += '_'
print(display)
end_of_game = False
while not end_of_game:
guess = input('Guess the letter: ').lower()
for position in range(word_length):
letter = chosen_word[position]
if letter == guess:
display[position] = letter
print(display)
if '_' not in display:
end_of_game == True
print('You win')
It prints, for example if chosen word is Apple, and guess from user is A, it shows "A _ _ _ _". And I need to fill all the spaces with correct letters, but what I ma getting is all letters but not the letter at index 0.
Aucun commentaire:
Enregistrer un commentaire