import random
import day7_hangman_words
chosen_word = random.choice(day7_hangman_words.word_list)
word_length = len(chosen_word)
#from day7_hangman_words import word_list
#chosen_word = random.choice(word_list)
lives = 6
end_of_game = False
from day7_hangman_art import logo,stages
print(logo)
#Testing code
#print(f"Pssst,the solution is {chosen_word}")
#Create blanks
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}")
#Check guessed letter
for position in range(word_length):
letter = chosen_word[position]
if letter == guess:
display[position] = letter
if guess not in chosen_word:
lives -= 1
print(f"You guessed {guess},that's not in the word.You lose a life.")
if lives == 0:
end_of_game = True
print("You lose.")
#Join all the elements in the list and turn it into a String
print(f"{' '.join(display)}" )
if "_" not in display:
end_of_game = True
print("You win.")
print(stages[lives])
day7_Udemy Python 100days
最新推荐文章于 2024-08-19 14:41:29 发布