MIT 6.100L Introduction to CS and Programming Using Python, Fall 2022 · Problem set 2, 1.1) Determine if the Player has Won — has_player_won · Dr. Ana Bell · CC BY-NC-SA 4.0 · MIT publishes no solution for this set; the worked solution is ours
Implement the function has_player_won according to its docstring. This function will be useful in determining when the hangman game has been won (i.e., the user has guessed all the letters in the secret word).
It is the first of three helper functions for MIT's Problem Set 2, Hangman: the computer picks a secret word, and the player tries to guess its letters one at a time. To approach the game, the problem is broken down into logical subtasks, creating three helper functions — has_player_won, get_word_progress and get_available_letters — which the game itself, hangman, will call.
The docstring's specification:
secret_word: string, the lowercase word the user is guessingletters_guessed: list (of lowercase letters), the letters that have been guessed so farTrue if all the letters of secret_word are in letters_guessed, False otherwiseImportant: Do NOT change the name, input parameters, or specification of the function! You may add helper functions, but changing the definition of the given function will cause the tests to fail.
Example usage:
print(has_player_won('apple', ['e', 'i', 'k', 'p', 'r', 's'])) # False print(has_player_won('face', ['f', 'c', 'a', 'e'])) # True
Adapted for the browser: MIT's hangman.py also loads the word list words.txt when it starts (load_words, choose_word); the starter leaves that out, since this function never uses the word list.