Files
python_bootcamp/007/task.py

41 lines
816 B
Python

import random
word_list = ["aardvark", "baboon", "camel"]
chosen_word = random.choice(word_list)
print(chosen_word)
placeholder = "_" * len(chosen_word)
print(placeholder)
found_letters = []
lives = 6
display = placeholder
while "_" in display and lives > 0:
guess = input("Select a letter:\n").lower()
display = ""
found_a_letter = False
for letter in chosen_word:
if letter == guess:
display += letter
found_a_letter = True
found_letters.append(letter)
elif letter in found_letters:
display += letter
else:
display += "_"
if found_a_letter == False:
lives -= 1
print(display)
if lives == 0:
print("Game over!")
else:
print("You won!")