Skip to content

Create Task requirements

TianbinLiu edited this page May 2, 2022 · 1 revision

Tianbin's work

One minute video for hangman game 3a. The purpose of the program, the hangman game, is to practice our coding skills with cs knowledge we had learned already. And also learned how to collaborate with others to do teamwork. The functionality of the program in the video is to produce two different results of the game. One is to produce the result of winning if you guess all the letters in the word correctly. And one is to produce the result of losing if you guess more than 7 wrong letters. The input of the program is what letters you guess and type it on the board. And the output of the program is the two results, win or lose, based on your input. 3b. i. The first program code segment must show how data have been stored in the list.

word_list = ["slippery","marriage","system","overeat","requirement","ballot","democratic","producer","victory","therapist","layer","action","blue","parade",
"inch","dough","curve","potato","tomato","request","dream","apparatus","outer","carrot","hangman","stick","wheel","car","galaxy","chest","best",
"number","space","cry","shock","lightning","veteran","man","woman","presidential","goat", "horse", "soccer", "football", "person", "people", 
"someone", "boot", "shoes", "diet", "stop", "name", "mute", "unmute", "piano", "guitar", "cat", "dog", "bread", "chocolate", "cake", "loyalty", "punish", "throne", "fight", "student", "garfield", "movie", "million", "blubber", "minion", "lamb", "goofy", "funny","science", "weather", 
"fridge", "punish", "creed", "virus", "pandemic", "medic", "assault", "helper", "sniper", "explosion", "attract", "exclusive", "search", "available"]

ii. The second program code segment must show the data in the same list being used, such as creating new data from the existing data or accessing multiple elements in the list, as part of fulfilling the program's purpose.

word = random.choice(word_list)

iii. Identifies the name of the list being used in this response

  • The name of the list being used in this response is "word_list" iv. Describes what the data contained in the list represent in your program
  • It represents the dictionary of the word that the game is being used. Every time the game start, it will pick one of the words in "word_list" and the player should guess the letters on chosen word correctly to win.

v. Explains how the selected list manages complexity in your program code by explaining why your program code could not be written, or how it would be written differently, if you did not use the list

  • The list helped us to manage the hundreds of words that were being used. Without the list, the code will be more complex because we need to type the whole word list into our code. 3c.
def hangman():
  word = random.choice(word_list)
  c_l = []
  w_l = []
  win = False
  def add_to_hangman():
    misses = len(w_l)
  while win == False and len(w_l) != 7:
    display = ""
    guess = input("Guess a letter: ")
    if guess in word:
      c_l.append(guess)
    else:
      w_l.append(guess)
      add_to_hangman()
    display = ""
    if len(w_l) == 5 and len(c_l) < 3:
      print("Hint: " + random.choice(word))
    for letter in word:
        if letter in c_l:
            display += letter + " "
        else:
            display += "_" + " "
            win = False
    if len(c_l) == len(word):
      win = True
    print(display)
  
    
  if win == True:
      print("You WIN!")
  else:
    print("You LOSE :( The answer was: " + word)
start = input("Welcome to the Hangman Game! Press 1 to start playing or press any other key to exit: ")
if start == "1":
  hangman()
if start != "1":
  print("Bye!")

iii. Describes in general what the identified procedure does and how it contributes to the overall functionality of the program

  • The identified procedure includes almost all the work we had done in this program. It used the word_list we made and formed the main function the program did. Like the code that decides the player win or loses. Like the hint appear when you had five wrong answers and three less correct answers.

iv. Explains in detailed steps how the algorithm implemented in the identified procedure works. Your explanation must be detailed enough for someone else to recreate it.

  • First It gives a produce name "hangman", then it picks a random word in "word_list", and makes two blank lists for correct letters you guess"c_l" and wrong letters you guess"w_l". Each time the letters you guess will send into the lists. And if you guess five more wrong letters and three less correct letters, it will give you a hint about a random letter in the word. Each time you guess the correct letters it will replace "" with "correct letter". And each time you guess the wrong letters it will remain "". If you guess more than seven wrong letters then you lose. 3d.
  1. First call:

The word is "dog", the input is "a", the letter "a" is not in the word "dog", it will add to the blank list "w_l". "_" remain the same, and you should type another guess.

  1. Second call:

The input is "d", the letter "d" is in the word "dog", it will add to the blank list "c_l", the letter "a" will replace "_" in the board. And you should keep guessing.

Clone this wiki locally