\[ \begin{align}\begin{aligned}\newcommand\blank{~\underline{\hspace{1.2cm}}~}\\% Bold symbols (vectors) \newcommand\bs[1]{\mathbf{#1}}\\% Poor man's siunitx \newcommand\unit[1]{\mathrm{#1}} \newcommand\num[1]{#1} \newcommand\qty[2]{#1~\unit{#2}}\\\newcommand\per{/} \newcommand\squared{{}^2} % % Scale \newcommand\milli{\unit{m}} \newcommand\centi{\unit{c}} \newcommand\kilo{\unit{k}} \newcommand\mega{\unit{M}} % % Angle \newcommand\radian{\unit{rad}} \newcommand\degree{\unit{{}^\circ}} % % Time \newcommand\second{\unit{s}} % % Distance \newcommand\meter{\unit{m}} \newcommand\m{\meter} \newcommand\inch{\unit{in}} \newcommand\feet{\unit{ft}} \newcommand\mile{\unit{mi}} \newcommand\mi{\mile} % % Volume \newcommand\gallon{\unit{gal}} % % Mass \newcommand\gram{\unit{g}} \newcommand\g{\gram} % % Frequency \newcommand\hertz{\unit{Hz}} \newcommand\rpm{\unit{rpm}} % % Voltage \newcommand\volt{\unit{V}} \newcommand\V{\volt} \newcommand\millivolt{\milli\volt} \newcommand\mV{\milli\volt} \newcommand\kilovolt{\kilo\volt} \newcommand\kV{\kilo\volt} % % Current \newcommand\ampere{\unit{A}} \newcommand\A{\ampere} \newcommand\milliampereA{\milli\ampere} \newcommand\mA{\milli\ampere} \newcommand\kiloampereA{\kilo\ampere} \newcommand\kA{\kilo\ampere} % % Resistance \newcommand\ohm{\Omega} \newcommand\milliohm{\milli\ohm} \newcommand\kiloohm{\kilo\ohm} % correct SI spelling \newcommand\kilohm{\kilo\ohm} % "American" spelling used in siunitx \newcommand\megaohm{\mega\ohm} % correct SI spelling \newcommand\megohm{\mega\ohm} % "American" spelling used in siunitx % % Inductance \newcommand\henry{\unit{H}} \newcommand\H{\henry} \newcommand\millihenry{\milli\henry} \newcommand\mH{\milli\henry} % % Temperature \newcommand\celsius{\unit{^{\circ}C}} \newcommand\C{\unit{\celsius}} \newcommand\fahrenheit{\unit{^{\circ}F}} \newcommand\F{\unit{\fahrenheit}} \newcommand\kelvin{\unit{\K}} \newcommand\K{\unit{\kelvin}}\\% Power \newcommand\watt{\unit{W}} \newcommand\W{\watt} \newcommand\milliwatt{\milli\watt} \newcommand\mW{\milli\watt} \newcommand\kilowatt{\kilo\watt} \newcommand\kW{\kilo\watt} % % Torque \newcommand\ozin{\unit{oz}\text{-}\unit{in}} \newcommand\newtonmeter{\unit{N\text{-}m}}\end{aligned}\end{align} \]

Apr 13, 2026 | 1428 words | 14 min read

12.2.1. PyWord#

Introduction#

Create a variation of the game Jotto (a predecessor to the hit game Wordle published in \(1955\)). This is a word guessing game where the player attempts to guess a secret word. After each guess, the program will reveal which letters from the guess are in the secret word and in the correct position, which are in the secret word but in the wrong position, and which are not in the secret word.

At the start of your program, the player will be presented with a main menu from which they can choose between viewing the rules, starting a new game, viewing the hall of fame, or exiting the program. If the player enters an invalid choice, the program should display an appropriate error message and let the player try again until a valid selection is made. The program should end if the player chooses to exit.

Note

Other than the function pick_game_words described below, you are free to design your program however you like. You may use object-oriented programming techniques, but are not required to do so.

Sample Output#

Note that incorrect input is handled by displaying an error message and then presenting the main menu again.

Use the values in Table 12.1 below to test your program.

Table 12.1 Test Cases#

Case

Inputs

1

Spam, #$%, quit, Q

Ensure your program’s output matches the provided samples exactly. This includes all characters, white space, and punctuation. In the samples, user input is highlighted like this for clarity, but your program should not highlight user input in this way.

Case 1 Sample Output

$ python3 final_project_login.py Welcome to PyWord.

----- Main Menu ----- (R)ules (N)ew Game (H)all of Fame (Q)uit

What would you like to do? Spam

Invalid choice. Please try again.

----- Main Menu ----- (R)ules (N)ew Game (H)all of Fame (Q)uit

What would you like to do? #$%

Invalid choice. Please try again.

----- Main Menu ----- (R)ules (N)ew Game (H)all of Fame (Q)uit

What would you like to do? quit

Invalid choice. Please try again.

----- Main Menu ----- (R)ules (N)ew Game (H)all of Fame (Q)uit

What would you like to do? Q

Goodbye.

1: Rules#

When the player chooses to view the rules, the program presents the rules as depicted below, and then returns to the main menu.

Sample Output#

Use the values in Table 12.2 below to test your program.

Table 12.2 Test Cases#

Case

Inputs

1

R, Q

Ensure your program’s output matches the provided samples exactly. This includes all characters, white space, and punctuation. In the samples, user input is highlighted like this for clarity, but your program should not highlight user input in this way.

Case 1 Sample Output

$ python3 final_project_login.py Welcome to PyWord.

----- Main Menu ----- (R)ules (N)ew Game (H)all of Fame (Q)uit

What would you like to do? R

PyWord is a word guessing game similar to Wordle. The goal is to guess three secret words in as few tries as possible. Each round you have six tries to guess the secret word. After each guess, you will receive feedback on your guess: ! means a correct letter in the correct position ? means a correct letter in the wrong position X means an incorrect letter

----- Main Menu ----- (R)ules (N)ew Game (H)all of Fame (Q)uit

What would you like to do? Q

Goodbye.

2: New Game#

After the player chooses to start a new game, they will be prompted to enter their player name. A new game will consist of three rounds, with each round using a different secret five letter word. The secret words are selected randomly from the words in the provided words.txt file.

To select the secret words, your program must call a function named pick_game_words. This function takes a list of all of the words in the words.txt file as its only argument and returns a list of three distinct words chosen at random. The returned words must all be lowercase and must be used in the same order as they appear in the returned list. No other portion of your program should involve random chance.

Player Input#

In each round, the player will be given up to a maximum of six turns to try to guess the secret word. Each guess can be any combination of five letters. If the player enters an invalid guess, the program should display an invalid input message and let the player try again without losing a turn. If the player enters q or Q, the game should end immediately, all progress from the current game (including any points earned) is discarded, and the program should return to the main menu.

Marking#

After each valid guess, the program will mark the letters of the guess with one of three characters. Letters that are in the secret word and in the correct position should be marked with a !, letters that are in the secret word but in the wrong position should be marked with a ?, and letters that are not in the secret word should be marked with an X.

Note

Note that a letter can be marked with a ? more times than that letter appears in the secret word.

The program will also display a marked alphabet where each letter is marked with either a blank space if not yet used in any guess, an ! if used in any guess in the correct location, a ? if used in any guess in the wrong location and never used in the correct location, or an X if used in any guess but the letter is not in the secret word.

Scoring#

A round ends when the player successfully guesses the secret word or they run out of turns. At the end of each round, the player earns points based on how many turns they used to guess the word, according to the formula

\[\text{points} = 2^{(\text{maximum_turns} - \text{turns_used})}\]

If the player runs out of turns, the program should display a failure message and reveal the secret word. If the player guesses the secret word, the program should display an accolade and the number of points they earned based on the number of turns remaining, as shown in the table below. Note that guessing correctly on the sixth turn earns the player \(1\) point. If the player fails to guess correctly after six turns, they will earn zero points.

Table 12.3 Accolades and points per turn remaining.#

Turns Remaining

Accolade

Points

6

Impossible

64

5

Genius

32

4

Magnificent

16

3

Impressive

8

2

Splendid

4

1

Great

2

0

Phew

1

Round Summary#

No matter how the round ends, once it is over, a summary of the marking hints provided for each guess should be displayed — one line of marks for each guess. This format makes it easy for a player to share their performance with others without revealing the word they were trying to guess.

End of Game#

Round two starts immediately after the end of round one, and round three starts immediately after the end of round two. At the end of the third round, the player’s total score for the game is the sum of their scores from each of the three rounds.

If the Hall of Fame has fewer than \(10\) entries, or if the player’s total score is larger than the lowest score in the Hall of Fame, the player’s score and name should be added at the appropriate position and a congratulatory message followed by the Hall of Fame table should be displayed. The table should have columns for rank, score, and player name, sorted from highest to lowest score. If multiple players have the same score, they should be listed in the order in which their scores were achieved. Otherwise, if the player’s score does not qualify, neither the congratulatory message nor the Hall of Fame table should be displayed.

Once the game is complete, the program returns to the main menu.

Sample Output#

Use the values in Table 12.4 below to test your program.

Table 12.4 Test Cases#

Case

Inputs

1

n, hacker, growl, perky, trace, q

2

n, Terry, stink, world, glory, group, grows, grown, q, q

3

n, Eric, onetwo, five, 33333, q, q

Ensure your program’s output matches the provided samples exactly. This includes all characters, white space, and punctuation. In the samples, user input is highlighted like this for clarity, but your program should not highlight user input in this way.

Case 1 Sample Output

$ python3 final_project_login.py Welcome to PyWord.

----- Main Menu ----- (R)ules (N)ew Game (H)all of Fame (Q)uit

What would you like to do? n Enter your player name: hacker

Round 1: 1? growl !!!!! ! ! ! ! ! growl abcdefghijklmnopqrstuvwxyz Genius! You earned 32 points this round.

Summary: Turn 1: !!!!!

Round 2: 1? perky !!!!! ! ! ! ! ! perky abcdefghijklmnopqrstuvwxyz Genius! You earned 32 points this round.

Summary: Turn 1: !!!!!

Round 3: 1? trace !!!!! ! ! ! ! ! trace abcdefghijklmnopqrstuvwxyz Genius! You earned 32 points this round.

Summary: Turn 1: !!!!!

Way to go hacker! You earned a total of 96 points and made it into the Hall of Fame!

--- Hall of Fame --- ## : Score : Player 1 : 96 : hacker 2 : 64 : Graham 3 : 52 : Graham 4 : 40 : Graham 5 : 38 : Michael 6 : 25 : Michael

----- Main Menu ----- (R)ules (N)ew Game (H)all of Fame (Q)uit

What would you like to do? q

Goodbye.

Case 2 Sample Output

$ python3 final_project_login.py Welcome to PyWord.

----- Main Menu ----- (R)ules (N)ew Game (H)all of Fame (Q)uit

What would you like to do? n Enter your player name: Terry

Round 1: 1? stink XXXXX X X X XX stink abcdefghijklmnopqrstuvwxyz 2? world ????X X X X? X? ?XX ? world abcdefghijklmnopqrstuvwxyz 3? glory !?!?X X ! X X? X! ?XX ? X glory abcdefghijklmnopqrstuvwxyz 4? group !!!XX X ! X X? X!X !XXX ? X group abcdefghijklmnopqrstuvwxyz 5? grows !!!!X X ! X X? X!X !XXX ! X grows abcdefghijklmnopqrstuvwxyz 6? grown !!!!X X ! X X? X!X !XXX ! X grown abcdefghijklmnopqrstuvwxyz You ran out of tries. The word was growl.

Summary: Turn 1: XXXXX Turn 2: ????X Turn 3: !?!?X Turn 4: !!!XX Turn 5: !!!!X Turn 6: !!!!X

Round 2: 1? q

Quitting game.

----- Main Menu ----- (R)ules (N)ew Game (H)all of Fame (Q)uit

What would you like to do? q

Goodbye.

Case 3 Sample Output

$ python3 final_project_login.py Welcome to PyWord.

----- Main Menu ----- (R)ules (N)ew Game (H)all of Fame (Q)uit

What would you like to do? n Enter your player name: Eric

Round 1: 1? onetwo

Invalid guess. Please enter 5 characters or 'Q' to quit.

1? five

Invalid guess. Please enter 5 characters or 'Q' to quit.

1? 33333

Invalid guess. Please only enter letters.

1? q

Quitting game.

----- Main Menu ----- (R)ules (N)ew Game (H)all of Fame (Q)uit

What would you like to do? q

Goodbye.

3: Hall of Fame#

From the main menu, the player can also choose to view the Hall of Fame. This option displays the same table presented to the user when they achieve a high score. Hall of Fame records should be saved in a file named hall_of_fame.txt. Each line in the file should be a player’s score followed by a comma, a space, and the player’s name. Only the top ten scores should be kept. The data from the file will be loaded when your program begins, and should be updated with any new high scores before your program ends.

Sample Output#

Use the values in Table 12.5 below to test your program.

Table 12.5 Test Cases#

Case

Inputs

1

h, q

Ensure your program’s output matches the provided samples exactly. This includes all characters, white space, and punctuation. In the samples, user input is highlighted like this for clarity, but your program should not highlight user input in this way.

Case 1 Sample Output

$ python3 final_project_login.py Welcome to PyWord.

----- Main Menu ----- (R)ules (N)ew Game (H)all of Fame (Q)uit

What would you like to do? h

--- Hall of Fame --- ## : Score : Player 1 : 64 : Graham 2 : 52 : Graham 3 : 40 : Graham 4 : 38 : Michael 5 : 25 : Michael

----- Main Menu ----- (R)ules (N)ew Game (H)all of Fame (Q)uit

What would you like to do? q

Goodbye.

4: Quit#

The program should only end if the player chooses to quit from the main menu. Before exiting, the program should save the current Hall of Fame data to hall_of_fame.txt.

Sample Output#

Use the values in Table 12.6 below to test your program.

Table 12.6 Test Cases#

Case

Inputs

1

q

Ensure your program’s output matches the provided samples exactly. This includes all characters, white space, and punctuation. In the samples, user input is highlighted like this for clarity, but your program should not highlight user input in this way.

Case 1 Sample Output

$ python3 final_project_login.py Welcome to PyWord.

----- Main Menu ----- (R)ules (N)ew Game (H)all of Fame (Q)uit

What would you like to do? q

Goodbye.

Deliverables#

Save your finished program as final_project_login.py, replacing login with your Purdue login. Then submit it along with all the deliverables listed in Table 12.7 below.

Table 12.7 Deliverables#

Deliverable

Description

final_project_login.py

Your finished program.