Ken Schaefer
4 months ago
1 changed files with 28 additions and 7 deletions
@ -1,13 +1,34 @@ |
|||||||
# Step 1 |
import random |
||||||
|
|
||||||
|
# Step 1 |
||||||
word_list = ["aardvark", "baboon", "camel"] |
word_list = ["aardvark", "baboon", "camel"] |
||||||
|
|
||||||
#TODO-1 Randomly choose a word from the word_list and assign it to a variable |
# Randomly choose a word from the word_list and assign it to a variable |
||||||
# called chosen_word |
# 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) |
||||||
|
|
||||||
#TODO-2 Ask the user to guess a letter and assign their answer to a variable |
# Ask the user to guess a letter and assign their answer to a variable |
||||||
# called guess. Make guess lowercase |
# called guess. Make guess lowercase |
||||||
|
|
||||||
#TODO-3 Check if the letter the user guessed (guess) is one of the letters in |
guess = input("Guess a letter: ").lower() |
||||||
# the chosen_word |
|
||||||
|
|
||||||
|
# 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) |
Loading…
Reference in new issue