Lab 5 - Iteration Patterns
Due Date and Links
-
Lab due on your scheduled lab day
-
Lab accepted for full credit until Monday, February 16, 11:59 pm Eastern
-
Direct autograder link https://autograder.io/web/project/3788
In this lab, you’ll write a word-guessing game. This will give you an opportunity to practice all the skills you’ve learned thus far. You will also get to use tuples, while loops, and functions like enumerate.
You should complete this lab in small groups of about four students. For all labs in EECS 183, to receive a grade, every student must individually submit the Lab assignment.
Starter Files
You can download the starter files using this link. It contains only word_guesser.py.
How the Game Works
As the Player
As the player of the game, you will be given a certain number of turns to guess a secret word. At each turn, you will be able to guess a letter. If the letter is in the word, the program will reveal the spot(s) at which the letter is. If the letter is not in the word, the program will display the letter in your “wrong guesses” list so you know not to guess it again. The program will flag duplicate guesses and ask you to guess again. Your objective is to guess the word before you run out of chances.
Here’s a sample of how the game looks when it is played. See the Sample Runs section below for more examples.
Word: _ _ _ _ _ Wrong guesses: [] Enter a letter: h Good guess! Word: h _ _ _ _ Wrong guesses: [] Enter a letter: a Wrong! Word: h _ _ _ _ Wrong guesses: ['a'] Enter a letter: p Wrong! Word: h _ _ _ _ Wrong guesses: ['a', 'p'] Enter a letter: p You already guessed that. Please try again. Enter a letter: l Good guess! Word: h _ l l _ Wrong guesses: ['a', 'p'] Enter a letter: e Good guess! Word: h e l l _ Wrong guesses: ['a', 'p'] Enter a letter: o Good guess! You won! The word was: hello
As the Programmer
As the programmer, there are a few pieces of information we have to keep track of in order to provide the gameplay experience. Specifically, we need three lists to keep track of the player’s guesses:
revealed: keeps track of which letters in the word the player has already guessed. The contents of this list get printed out every turn. In the sample run above, it is printed right after “Word:”. Unknown letters are represented by underscores (_). For example, if the word to be guessed ishello, and the player has made no guesses yet,revealedshould be:[_, _, _, _, _]because none of the letters have been revealed yet.already_guessed: keeps track of all the guesses the player has made. We use it to detect duplicate guesses.wrong_guesses: keeps track of the wrong guesses that the user has made. The contents of this list get printed out every turn (in the sample run above, it is printed out right after “Wrong guesses:”).
Given the sample run above, where the word to guess is hello, here is how each list should look after the first couple of guesses:
At the beginning:
revealed: [_, _, _, _, _]already_guessed: []wrong_guesses: []
After guess 1 (h):
revealed: ["h", _, _, _, _]already_guessed: ["h"]wrong_guesses: []
After guess 2 (a):
revealed: ["h", _, _, _, _]already_guessed: ["h", "a"]wrong_guesses: ["a"]
You will be using these three lists to implement the functions below. You may name these list variables whatever makes sense to you in your code, but be sure you have all three.
Tasks to Complete
- To complete the lab, you need to do the following steps:
- Write the implementations for the functions in
word_guesser.py:init_game()print_revealed()get_guess()make_guess()play_game()
- Test your code by playing the game yourself.
- Submit your
word_guesser.pyto the autograder.
init_game()
This function takes in the word that the player is supposed to guess and initializes the three lists mentioned above. Since the player has not made any guesses yet, the wrong_guesses and already_guessed lists should be empty, and the revealed list should consist of the correct number of underscores. The provided return statement is just a placeholder; adjust it and add code as needed to return the lists according to the RME.
print_revealed()
This function takes in the current revealed list and prints it in string format. For example, if the revealed list is currently [_, _, "l", "l", _], then the function should print out:
Word: _ _ l l _
Whitespace matters for this function! Ensure you are printing each element of your list with a space in the middle. Use the .join method in your code.
get_guess()
This function prompts the player to enter a guess. Should the player enter an invalid guess, the function will output an error message and continue prompting the user for a guess until they give a valid one.
There are two ways a guess can be invalid:
- The guess is not a single letter. (If the user inputs multiple letters, or inputs numbers, the guess is invalid.)
- Resulting error message:
Your guess should be one alphabetical character.
- Resulting error message:
- The guess is a single letter, but that letter has already been guessed.
- Resulting error message:
You already guessed that. Please try again.
- Resulting error message:
The order you check for the errors matters for correct output. If the guess is 1+ characters or has non-alphabetical characters, you should prompt the player for input again without checking if the guess has already been made.
Here is an example of how the error-handling should look:
Word: _ _ _ _ _ Wrong guesses: [] Enter a letter: qwerty Your guess should be one alphabetical character Enter a letter: qwerty Your guess should be one alphabetical character Enter a letter: a Wrong! Word: _ _ _ _ _ Wrong guesses: ['a'] Enter a letter: a You already guessed that. Please try again.
make_guess()
This function updates the three lists given a guess letter.
If the letter is in the word, then find out which index / indices the letter is at and replace those indices in revealed with the letter. For example, if the word is hello and the guess is l, the revealed list (which originally looked like [_, _, _, _, _]) should now look like [_, _, "l", "l", _]. Remember that the same letter may be in multiple places in the word, and you should reveal all of them.
Use the enumerate function for this!
If the guess is not in the word, add it to the wrong_guesses list.
In all cases, add the guess to the already_guessed list.
play_game()
This function is responsible for creating the infrastructure to play the game.
The player should get at most (word length) * 2 guesses to reveal the whole word. However, since there are only 26 letters in the alphabet, if (word length) * 2 exceeds 26, then only allow the user to make at maximum 26 guesses. Only count valid guesses towards this total: invalid or duplicated guesses do not count.
The player has won if all letters in the word have been revealed.
Write the function according to the following steps:
- Initialize all three lists using
init_game. - While the player has not won and still has remaining guesses:
- Print the
revealedlist usingprint_revealed. - Print the
wrong_guesseslist using theprintfunction. - Get the player’s guess using
get_guess. - Update the three lists using
make_guess. - If the guess is correct, print
Good guess!. If the guess is incorrect, printWrong!. In both cases, print a blank line after.
- Print the
- If the player has won, print
You won! The word was: <word>. If the player ran out of guesses and lost, printYou ran out of guesses! The word was: <word>.
Sample Runs
You can replicate these tests on your own by changing the argument passed to play_game() in the main guard at the bottom of vibe_checker.py. For example:
if __name__ == "__main__":
# this used to be play_game("hello")
play_game("cat")
Sample Run 1: Word is “hello”
Word: _ _ _ _ _ Wrong guesses: [] Enter a letter: h Good guess! Word: h _ _ _ _ Wrong guesses: [] Enter a letter: l Good guess! Word: h _ l l _ Wrong guesses: [] Enter a letter: a Wrong! Word: h _ l l _ Wrong guesses: ['a'] Enter a letter: e Good guess! Word: h e l l _ Wrong guesses: ['a'] Enter a letter: o Good guess! You won! The word was: hello
Sample Run 2: Word is “cat”
Word: _ _ _ Wrong guesses: [] Enter a letter: b Wrong! Word: _ _ _ Wrong guesses: ['b'] Enter a letter: u Wrong! Word: _ _ _ Wrong guesses: ['b', 'u'] Enter a letter: f Wrong! Word: _ _ _ Wrong guesses: ['b', 'u', 'f'] Enter a letter: w Wrong! Word: _ _ _ Wrong guesses: ['b', 'u', 'f', 'w'] Enter a letter: a Good guess! Word: _ a _ Wrong guesses: ['b', 'u', 'f', 'w'] Enter a letter: n Wrong! You ran out of guesses! The word was: cat
Sample Run 3: Word is “cat”
Word: _ _ _ Wrong guesses: [] Enter a letter: a Good guess! Word: _ a _ Wrong guesses: [] Enter a letter: a You already guessed that. Please try again. Enter a letter: a You already guessed that. Please try again. Enter a letter: a You already guessed that. Please try again. Enter a letter: a You already guessed that. Please try again. Enter a letter: a You already guessed that. Please try again. Enter a letter: t Good guess! Word: _ a t Wrong guesses: [] Enter a letter: m Wrong! Word: _ a t Wrong guesses: ['m'] Enter a letter: p Wrong! Word: _ a t Wrong guesses: ['m', 'p'] Enter a letter: c Good guess! You won! The word was: cat
Sample Run 4: Word is “cat”
Word: _ _ _ Wrong guesses: [] Enter a letter: aw Your guess should be one alphabetical character. Enter a letter: aw Your guess should be one alphabetical character. Enter a letter: a Good guess! Word: _ a _ Wrong guesses: [] Enter a letter: a You already guessed that. Please try again. Enter a letter: t Good guess! Word: _ a t Wrong guesses: [] Enter a letter: c Good guess! You won! The word was: cat
How to Submit
- When ready to submit to the autograder, visit https://autograder.io/web/project/3788. You will submit your
word_guesser.pyfile which should contain your solution for this lab.
IMPORTANT: For all labs in EECS 183, to receive a grade, every student must individually submit the Lab Submission. Late submissions for Labs will not be accepted for credit. For this lab, you will receive ten submissions per day with feedback.
- Once you receive a grade of 10 of 10 points from the autograder you will have received full credit for this lab.
Copyright and Academic Integrity
© 2026 .
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.
All materials provided for this course, including but not limited to labs, projects, notes, and starter code, are the copyrighted intellectual property of the author(s) listed in the copyright notice above. While these materials are licensed for public non-commercial use, this license does not grant you permission to post or republish your solutions to these assignments.
It is strictly prohibited to post, share, or otherwise distribute solution code (in part or in full) in any manner or on any platform, public or private, where it may be accessed by anyone other than the course staff. This includes, but is not limited to:
- Public-facing websites (like a personal blog or public GitHub repo).
- Solution-sharing websites (like Chegg or Course Hero).
- Private collections, archives, or repositories (such as student group “test banks,” club wikis, or shared Google Drives).
- Group messaging platforms (like Discord or Slack).
To do so is a violation of the university’s academic integrity policy and will be treated as such.
Asking questions by posting small code snippets to our private course discussion forum is not a violation of this policy.