Intro to Python
Share
Explore

Guess the Word

In this section, you’ll be programming your own “guess the word” game.
We’ve broken down the project into four parts.
Search
Task
Section
Status
1
🎲 Handle user input
Guess the Word
Not Started
2
🎲 Keep track of guesses
Guess the Word
Not Started
3
🎲 Show the word progress
Guess the Word
Not Started
4
🎲 End the game
Guess the Word
Not Started
5
🍦 Add bonus features to your game
Guess the Word
Not Started
No results from filter

Setup
Go to and click on the “Fork” button at the top. This will create your own copy of the code.
Optional: The starter code has a file called codebank.txt. If you don’t feel comfortable writing your own code from scratch, you can copy the code snippets for each part. You will need to find the right place to use each piece of code, and you’ll need to add your own indentation.
Part 1: Handle user input
Your first task is to have the user guess a letter and let them know if the letter is in your word. To start, we'll let the user guess an infinite number of times.
Example
Assume the word to guess is “collaborative”.
The red text represents user input (as opposed to program output).
Guess a letter: a
Yes, the letter a is in the word.
Guess a letter: z
No, the letter z is not in the word.
Part 2: Keep track of guesses
Your next task is to keep track of how many letters the user has guessed and how many guesses they have remaining.
If the player guesses a letter they have already guessed, do not count it as another guess.
Example
Assume the word to guess is “collaborative”.
The red text represents user input (as opposed to program output).
Guess a letter: a
Yes, the letter a is in the word.
You have 9 guess(es) remaining.
----
Guess a letter: a
You have already guessed a.
Yes, the letter a is in the word.
You have 9 guess(es) remaining.
----
Guess a letter: z
No, the letter z is not in the word.
You have 8 guess(es) remaining.
----
Part 3: Show the word progress
Your next task is to reveal the location of the guessed letters in the word.
Write a function get_word_progress that takes as input the word to guess and a set of letters that have been guessed. It should return a string that represents the word to guess with unguessed letters replaced by the * character.
Example:
>> word_to_guess = 'collaborate'
>> guesses = set(['a', 'b'])
>> get_word_progress(word_to_guess, guesses)
'****ab**a**'
Example (game play)
Assume the word to guess is “collaborative”.
The red text represents user input (as opposed to program output).
Guess a letter: a
Yes, the letter a is in the word.
****a***a**
You have 9 guess(es) remaining.
----
Guess a letter: l
Yes, the letter l is in the word.
**lla***a**
You have 8 guess(es) remaining.
----
Guess a letter: z
No, the letter z is not in the word.
**lla***a**
You have 7 guess(es) remaining.
----
Part 4: End the game
The last task is to end the game when the player has either guessed the word or reached the guess limit.
Write a function is_word_guessed that takes as input the word to guess and a set of letters that have been guessed. It should return True if all the letters in the word have been guessed and False otherwise.
Example:
>> word_to_guess = 'collaborate'
>> guesses = set(['a', 'b'])
>> is_word_guessed(word_to_guess, guesses)
False
>> guesses = set(['a', 'b', 'c', 'e', 'l', 'o', 'r', 't'])
>> is_word_guessed(word_to_guess, guesses)
True
Example (winning game)
Assume the word to guess is “dog”.
The red text represents user input (as opposed to program output).
Guess a letter: d
Yes, the letter d is in the word.
d**
You have 9 guess(es) remaining.
----
Guess a letter: g
Yes, the letter g is in the word.
d*g
You have 8 guess(es) remaining.
----
Guess a letter: o
Yes, the letter o is in the word.
dog
You have 7 guess(es) remaining.
----
You won!
Example (losing game)
Assume the word to guess is “dog”.
The red text represents user input (as opposed to program output).
Guess a letter: h
No, the letter h is not in the word.
d*g
You have 2 guess(es) remaining.
----
Guess a letter: i
No, the letter i is not in the word.
d*g
You have 1 guess(es) remaining.
----
Guess a letter: j
No, the letter j is not in the word.
d*g
You have 0 guess(es) remaining.
----
You lost :(
Extensions
If you finish early and are looking for ways to extend your game, here are some ideas:
Create a random list of words and select a random word to guess each time (Hint: the may be helpful).
Verify the player’s guess and print an error message if they guess something that’s not a letter in the alphabet.
Let the user guess an entire word.
Your own idea

If you used the codebank for your solution, try redoing this challenge by writing your own code from scratch!
Solution
View the .


Share
 
Want to print your doc?
This is not the way.
Try clicking the ⋯ next to your doc name or using a keyboard shortcut (
CtrlP
) instead.