Project Description

Write a Turtle graphics program that plays the game of Hangman:

en.wikipedia.org/wiki/Hangman_(game) The program begins by picking one of the following names of famous computer scientists at random:

  • ALAN TURING
  • DONALD KNUTH
  • ADA LOVELACE
  • GRACE HOPPER
  • GORDON MOORE

The player then guesses letters until he/she gets the answer right (and wins) or makes a total of six incorrect guesses (and loses). After each incorrect guess, a new body part is drawn: first the head, then the body, then the left arm, then the right arm, then the left leg and then the right leg: six incorrect guesses means that the player has lost. The space in each name is not considered part of the answer the user needs only to guess the letters.

Use a textinput window to take one letter at a time from the user. The user may enter a lowercase or uppercase letter as input, but the program should process all letters as uppercase. When the user guesses a letter correctly, the letter (or letters, if the letter is repeated in the word) should appear over its correct blank spot(s) in the word. If the user enters multiple letters at a single time, use only the first letter entered. You may assume that the user enters at least one letter and never enters nonletters.

The entire alphabet should also be drawn on the screen, with guessed letters shown in red, as in the examples below. If a user guesses the same letter a second time, a new body part should not be added and the second guess should not be counted against the user.

As part of this assignment you must define and call the following functions in your program where you feel it is appropriate to do so. You should decide what parameters make sense for each function to take:

  • updateGuess Updates the data structures that store the users guesses at the correct answer. For example, if you have a list of the letters the user has guessed (both correctly and incorrectly), then this function will update that list with the new guessed letter.
  • drawGuess Draws the users guess on the screen (i.e., the letters and dashes). No dash should be drawn for the space in the computer scientists name.
  • drawAlphabet Draws all 26 letters of the alphabet on screen, with unused letters in green and guessed letters in red.
  • drawMan Draws the hangman figure on the screen. You may find it useful to have a global variable that keeps track of the number of guesses. This variable will determine which body parts to draw

You may define any additional functions you like, but you must write these four functions for full credit.

Data Structures

You will need to think carefully about what variables and data structures (e.g., strings, lists) you will need to complete the assignment. You might wish to make a list of letters to keep track of which letters the user has already guessed (both correctly and incorrectly guessed). Having this list would help you to decide which letters of the alphabet to draw in green and which letters should be drawn in red.

Naturally, you will also need to keep track of the users progress in guessing the final answer. This could be done with a string or a list. One idea is this: create a list containing a number of space characters equal to the length of the computer scientists name. For example suppose the correct answer is ALAN TURING. That string is 11 characters in length, including the space. So we make a list of 11 spaces: [" "," "," "," "," "," "," "," "," "," "," "] As the user makes correct guesses, the spaces are replaced with actual letters. For example, suppose the user has so far correctly guessed that A and N are in the answer. Then this list would contain the following: ["A"," ","A","N"," "," "," "," "," ","N"," "]

This is only one possible way to implement this data structure. Perhaps you will come up with your own!

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.