You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
import random
|
|
|
|
|
|
|
|
# Step 1
|
|
|
|
word_list = ["aardvark", "baboon", "camel"]
|
|
|
|
|
|
|
|
# Randomly choose a word from the word_list and assign it to a variable
|
|
|
|
# called chosen_word
|
|
|
|
# chosen_word = word_list[random.randint(1, len(word_list) - 1)]
|
|
|
|
|
|
|
|
chosen_word = random.choice(word_list)
|
|
|
|
print(chosen_word)
|
|
|
|
|
|
|
|
# Create an empty list called display. For each letter in the chosen_word,
|
|
|
|
# add a "_" to display
|
|
|
|
|
|
|
|
display = []
|
|
|
|
for _ in chosen_word:
|
|
|
|
display += "_"
|
|
|
|
print(display)
|
|
|
|
|
|
|
|
# Ask the user to guess a letter and assign their answer to a variable
|
|
|
|
# called guess. Make guess lowercase
|
|
|
|
|
|
|
|
guess = input("Guess a letter: ").lower()
|
|
|
|
|
|
|
|
# Loop through each position in the chosen_word, if the letter matches then
|
|
|
|
# replace the _ with the letter
|
|
|
|
for pos in range(len(chosen_word)):
|
|
|
|
letter = chosen_word[pos]
|
|
|
|
if letter == guess:
|
|
|
|
display[pos] = letter
|
|
|
|
|
|
|
|
# Print display and you should see the letter in the correct position
|
|
|
|
print(display)
|