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.

34 lines
926 B

4 months ago
import random
4 months ago
4 months ago
# Step 1
4 months ago
word_list = ["aardvark", "baboon", "camel"]
4 months ago
# 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)
4 months ago
4 months ago
# Ask the user to guess a letter and assign their answer to a variable
# called guess. Make guess lowercase
4 months ago
4 months ago
guess = input("Guess a letter: ").lower()
4 months ago
4 months ago
# 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)