guess the word python
import random
# Put words to guess inside the array
words = []
word = random.choice(words)
n = len(word)
print("Guess the word")
guesses = ''
#number of turn is equal to the legnth of the word stored in 'n'
turns = n
while turns > 0:
#counts the number of wrong choices
failed = 0
for char in word:
if char in guesses:
print(f"\t{char}")
else:
print(f"\t_")
failed += 1
if failed == 0:
print("Congratulations! you Win!\n")
print(f"The word is: {word}")
break
guess = input("\nguess a letter: ")
guesses += guess
#decrements the turns for every wrong guess
if guess not in word:
turns -= 1
print("Wrong")
print(f"You have, {turns} more guesses")
if turns == 0:
print(f"You Loose, The word is {word}.")