-
210402 TILTIL/202104 2021. 4. 2. 23:28
1.English
I wish I went to abroad for travel but I can’t now.
Not unless everyone gets over Corona virus together.
I am working so hard
Not as hard as I am though
2.Udemy Python
while loop
# Hangman
import random from replit import clear from hangman_words import word_list from hangman_art import stages, logo chosen_word = random.choice(word_list) word_length = len(chosen_word) end_of_game = False lives = len(stages) - 1 print(logo) #Create blanks display = [] for _ in range(word_length): display += "_" while not end_of_game: guess = input("Guess a letter: ").lower() clear() if guess in display: print(f"{guess} has already been guessed, please choose other one") #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 #Join all the elements in the list and turn it into a String. print(f"{' '.join(display)}") #Check if user is wrong. if guess not in chosen_word: print(f"You guessed {guess}, that is not in the chosen word. You lose a life. ") lives -= 1 if lives == 0: end_of_game = True print("You lose.") #Check if user has got all letters. if "_" not in display: end_of_game = True print("You win.") print(stages[lives])
'TIL > 202104' 카테고리의 다른 글
210416 TIL (0) 2021.04.16 210413 TIL (0) 2021.04.14 210406 TIL (0) 2021.04.07 210405 TIL (0) 2021.04.06 210401 TIL (0) 2021.04.01