I'm trying to code a hangman kind of thing but even after the word is guessed correctly the loop continues. It seems like the bit that isn't working is the if word == ("".join(userword)) bit at the end, but I don't know what I'm doing wrong .
import random
word = random.choice(["apple", "orange", "pineapple"])
word = list(word)
life = 5
userword = []
for i in range (len(word)):
userword.append("_")
while life > 0:
print("".join(userword))
print("enter a letter")
letter = input()
letterinword = False
for i in range(len(word)):
if word[i] == letter:
userword[i] = letter
letterinword = True
if letterinword == False:
life = life - 1
if word == ("".join(userword)):
break
Aucun commentaire:
Enregistrer un commentaire