This exercise is Part 3 of 3 of the Hangman exercise series. The other exercises are: Part 1 and Part 2.
You can start your Python journey anywhere, but to finish this exercise you will have to have finished Parts 1 and 2.
In this exercise, we will finish building Hangman. In the game of Hangman, the player only has 6 incorrect guesses (head, body, 2 legs, and 2 arms) before they lose the game.
In Part 1, we loaded a random word list and picked a word from it. In Part 2, we wrote the logic for guessing the letter and displaying that information to the user. In this exercise, we have to put it all together and add logic for handling guesses.
Copy your code from Parts 1 and 2 into a new file as a starting point. Now add the following features:
Optional additions:
"You have 4 incorrect guesses left"
, display some picture art for the Hangman. This is challenging - do the other parts of the exercise first!
Your solution will be a lot cleaner if you make use of functions to help you!
Here is a sample solution from a reader that uses the solutions to Parts 1 and 2, and just puts them on one file:
And here’s my solution, making more heavy use of functions: