Pag 145
That's all the functions we are creating for this game! getRandomWord(wordList) will take a list of strings passed to it as a parameter, and return one string from it. That is how we will choose a word for the player to guess. displayBoard(HANGMANPICS, missedLetters, correctLetters, secretWord) will show the current state of the board, including how much of the secret word the player has guessed so far and the wrong letters the player has guessed. This function needs four parameters passed to work correctly. HANGMANPICS is a list of strings that hold the ASCII art for each possible hangman board. correctLetters and missedLetters are strings made up of the letters that the player has guessed that are in and not in the secret word. And secretWord is the secret word the player is trying to guess. This function has no return value. getGuess(alreadyGuessed) takes a string of letters the player has already guessed and will keep asking the player for a letter that is a letter that he hasn't already guessed. (That is, a letter that is not in alreadyGuessed. This function returns the string of the acceptable letter the player guessed. playAgain() is a function that asks if the player wants to play another round of Hangman. This function returns True if the player does and False if the player doesn't. We're done with Hangman. This has been a long chapter, and several new concepts have been introduced. But Hangman has been our most advanced game yet. As your games get more and more complex, it'll be a good idea to sketch out a flow chart on paper of what happens in your program. Methods are functions that are associated with values. The return values of methods depend on the values that the method is associated with. for loops iterate over the items in a list. The range() function is often used with for loops because it is an easy way to create lists of sequential numbers. Else if statements (which use the elif keyword) will execute their block if their condition is True and the previous if and elif conditions are False Dictionaries are very similar to lists except that they can use any value for an index. The indexes in dictionaries are called keys. Keys can be strings, integers, or any value of any data type.