코딩 공부/Python

Hangman Step4

recordmastd 2023. 1. 24. 14:07

틀렸을 때 패널티를 주자

while not end_of_game:
    guess = input("Guess a letter: ").lower()

    #Check guessed letter
    for position in range(word_length):
        letter = chosen_word[position]
        # print(f"Current position: {position}\n Current letter: {letter}\n Guessed letter: {guess}")
        if letter == guess:
            display[position] = letter

    #TODO-2: - If guess is not a letter in the chosen_word,
    #Then reduce 'lives' by 1. 
    #If lives goes down to 0 then the game should stop and it should print "You lose."
        else:
          lives -= 1
else문을 추가하면 _갯수마다 lives가 까여서 한 번 틀릴 때마다 -1이상 까임

for문에서 벗어난 if문을 새로 만들자