반응형
import random
from hangman_art import logo
from hangman_words import word_list
from hangman_art import stages
chosen_word = random.choice(word_list)
word_length = len(chosen_word)
end_of_game = False
lives = 6
print(logo)
print(f'Pssst, the solution is {chosen_word}.')
display = []
for _ in range(word_length):
display += "_"
while not end_of_game:
guess = input("Guess a letter: ").lower()
if guess in display:
print(f"You've already guessed {guess}")
for position in range(word_length):
letter = chosen_word[position]
if letter == guess:
display[position] = letter
if guess not in chosen_word:
print(f"You guessed {guess}, that's not in the word. You lose a life.")
lives -= 1
if lives == 0:
end_of_game = True
print("You lose.")
print(f"{' '.join(display)}")
if "_" not in display:
end_of_game = True
print("You win.")
print(stages[lives])
반응형
'파이썬 > exercise' 카테고리의 다른 글
8-2. python prime number checker (0) | 2023.01.04 |
---|---|
8-1. python function - math ceil (0) | 2023.01.04 |
5-4. python 비밀번호 생성기(shuffle) (0) | 2023.01.04 |
5-3. python 짝수의 합 구하기(for반복문 연습) (0) | 2023.01.04 |
5-2. python 최고/최소 점수얻기(for반복문 연습) (0) | 2023.01.04 |