mercredi 15 janvier 2020

How to get through the whole list with if statement even if the first conditin was met?

this is for hangman and when the if statement finds the first letter then it stops, it doesnt go further throught the list so it doesnt add the duplicates for example if a word countaians two a letters, then it will only add the first one. I hope i was clear enough! Thank you for help in advence!

'''
words = ["harry potter", "i love you forever", "neverland", "pockahontas"]
lives = 3
hangman = list(random.choice(words))
copy_of_hangman = hangman.copy()
print(copy_of_hangman)
for i in range(-6, 6, 2):
    copy_of_hangman[i] = "_"
print(copy_of_hangman)
while lives != 0:
    guess = input("Make your guess: ")
    for letter in hangman:
        if letter == guess:
            copy_of_hangman[hangman.index(letter)] = guess
            print(" ".join(copy_of_hangman))
'''

Aucun commentaire:

Enregistrer un commentaire