samedi 17 août 2019

Keep calling a function until a condition is met Python

I want to create a hangman game. I want it to keep calling x and printing new_word until there is no "_". I have tried it but the slots keep refreshing. It keeps reprinting. It won't update the value itself.

word = 'EVAPORATE'
wordlist = list(word)
dict = dict(enumerate(wordlist))

slots = list('_' * len(word))

x = input("Guess the letter: ")

def game():    
    for a,b in dict.items():
        if b == x:
            slots[a] = x
            new_word = ' '.join(slots)
    print(new_word)

game()

Aucun commentaire:

Enregistrer un commentaire