You are creating a letter guessing game app called Guessing Letter Game. The app picks a letter from a to z ( 26 case-insensitive characters). Then, the user makes guesses to find the letter. To represent letters from lowercase a to z, you may use a pre-initialized string in Python. You may use the following import statement. from string import ascii_lowercase The UML diagram of Guessing Letter Game is on the next page.
still_playing: a Bool attribute, set to True if the player is still playing the game. list_games: a class variable to contain information for All games. init_(self, user_name): to initialize information about a game. * In this method, you will need to use a 'try/except' clause to handle 'NoUserFoundError' and 'NotLetterError.' * (Hint) To print the correct output of 'NoUserFoundError' and 'NotLetterError', you may refer to the following syntax. msg = " ".join(e.args) message =f"{e._class_._name_}:{msg}"? display_info(self): to display information about a game. Please refer to the Example Interaction section. pick_letter(self): a private method for the GuessingLetterGame class to pick a letter for the computer. This method randomly selects a letter from ascii_lowercase. play(self, value): to take a user's guess and compare it with the computer's letter. The user can play only when a game is initialized and has not ended. * In this method, three user-defined exceptions will be raised and they will be handled with a try/except clause. > NotLetterError: raised if the user's guess is not in ascii_lowercase. For example, the user's guess is ' 4 .' > LetterBefore: raised if the computer's letter comes before the user's guess. For example, the computer's letter is ' b ' while the user's guess is ' f.' > LetterAfter: raised if the computer's letter comes after the user's guess. For example, the computer's letter is ' s ' while the user's guess is ' m.' * If the user guesses correctly, the method ends the game and display that he/she has guessed correctly. > It displays the list of user's guesses. > It calls display_info() as well. end(): to set appropriate attributes to end a game. * This method also updates the players' total_guess and total_correct values accordingly.
\begin{tabular}{|l|l|} \hline \multicolumn{1}{|c|}{ GuessingLetterGame } \\ \cline { 2 - 3 } & \( \begin{array}{l}\text { + user_name* } \\ \text { +_user_name } \\ + \text { secret_letter } * \\ + \text { +secret_letter } \\ + \text { list_guesses } \\ + \text { initialized } \\ + \text { correctly_guessed } \\ + \text { still_playing } \\ + \text { list_games } *\end{array} \) \\ \hline methods \\ + __init__() \\ + display_info() \\ + _pick_letter() \\ + play() \\ + end() \end{tabular} ? : property ?? : class variable Stand-alone functions - summary_guessinglettergame(list) - summary_players(list) The Player class contains information about players, a list of ALL players and twc methods. user_name: property, the user name of a player * In the user_name setter method, you will need to check if the user name is already taken. * If the user name is already taken, it will raise 'DuplicateUserNameErrc which is a user-defined Exception in GLG. * (Hint) Please refer to the example on Page 497 for a getter and a sette methods. * (Hint) To print the correct output of 'DuplicateUserNameError', pleas refer to the example on Page 470 of the textbook. _user_name: the private attribute for the user_name property. first_name, last_name: the first and last names of a player. total_guess: total guesses the player has made so far. It is updated by GuessingLetterGame.end() only. total_correct: total correct guesses the player has made. It is updated by GuessingLetterGame.end() only. list_players: a class variable to contain information for ALL players.
init_(self, user_name, first_name, last_name): to initialize information about a player. * In this method, you will need to use a 'try/except' clause to handle 'DuplicateUserNameError.' * (Hint) To print the correct output of 'DuplicateUserNameError', you may refer to the following syntax. \[ \begin{array}{l} \text { msg = " ".join(e.args) } \\ \text { message }=f "\left\{e . \_ \text {class____name__ }\right\}:\{\text { msg }\} " \end{array} \] display_info(self): to display information about a player. Please refer to the Exampl? Interaction section. - The GuessingLetterGame class contains information about games, a list of ALL games and five methods. user_name: property, the user name of a player * In the user_name setter method, you will need to check if the user name is stored in Player.list_players. * If there is no user in Player.list_players, it will raise 'NoUserFoundError', which is a user-defined Exception in GLG. * (Hint) Please refer to the example on Page 497 for a getter and a setter methods. * (Hint) To print the correct output of 'NoUserFoundError', please refer to the example on Page 470 of the textbook. _user_name: the private attribute for the user_name property secret_letter: property, the letter chosen by the computer * In the secret_letter setter method, you will need to check if the value is in ascii_lowercase. * If the value is not in ascii_lowercase, it will raise 'NotLetterError', which is a user-defined Exception in GLG. * (Hint) Please refer to the example on Page 497 for a getter and a setter methods. * (Hint) To print the correct output of 'NoUserFoundError', please refer to the example on Page 470 of the textbook. _secret_letter: the private attribute for the secret_letter property. list_guesses: contains a list of guesses for the game. Initialized: a Bool attribute, set to True if the object is initialized. correctly_guessed: a Bool attribute, set to True if the player guessed the letter correctly.