Background Information This assignment tests your understanding of and ability to apply the programming concepts we have covered in the unit so far, including the usage of variables, input and output, data types, selection, iteration, functions and data structures. Above all else, it tests your ability to design and then implement a solution to a problem using these concepts. Assignment Overview You are required to design and implement a "Word Game" program in which the user must identify a randomly selected "password" from a list of 8 words. The 8 words are selected at random from the list of 100 words in the starter file (word_game.py) provided to you with this assignment brief. Please use the starter file as the basis of your assignment code. The user has 4 attempts in which to guess the password. Whenever they guess incorrectly, they are told how many of the letters are the same between the word they guessed and the password. For example, if the password is "COMEDY" and they guessed "MOULDY", they would be told that 3/6 letters were correct due to the O, D and Y being the same. Note that a letter must be in the correct position to be correct. e.g. In the example above, both words contain the letter "M" but it is in a different position in the word so it is not counted as a correct letter. Using this information, the user can make increasingly knowledgeable guesses and win the game by selecting the password within four guesses. If the user fails to select the correct word within 4 guesses, they lose the game. Pseudocode As emphasised by the case study of Module 5, it is important to take the time to properly design a solution before starting to write code. Hence, this assignment requires you to write and submit pseudocode of your program design as well as the code for the program. Furthermore, while your tutors are happy to provide help and feedback on your assignment work throughout the semester, they will expect you to be able to show your pseudocode and explain the design of your code. You will gain a lot more benefit from pseudocode if you actually attempt it before trying to code your program - even if you just start with a rough draft to establish the overall program structure, and then revise and refine it as you work on the code. This back and forth cycle of designing and coding is completely normal and expected, particularly when you are new to programming. The requirements detailed on the following pages should give you a good idea of the structure of the program, allowing you to make a start on designing your solution in pseudocode. Write a separate section of pseudocode for each function you define in your program so that the pseudocode for the main part of your program is not cluttered with function definitions. Ensure that the pseudocode for each of your functions clearly describes the parameters that the function receives and what the function returns back to the program. It may help to think of the pseudocode of your program as the content of a book, and the pseudocode of functions as its appendices: It should be possible to read and understand a book without necessarily reading the appendices, however they are there for further reference if needed. Only one function is required in this assignment (detailed later in the assignment brief). Program Requirements These requirements begin where the starter file ends - after defining the "candidateWords" list. In the following information, numbered points describe a core requirement of the program, and bullet points (in italics) are additional details, notes and hints regarding the requirement. Ask your tutor if you do not understand a requirement or would like further details. 1. Set up the game by creating a list of 8 randomly selected words from candidateWords and then randomly select one of those words to be the password. Also create a boolean variable to keep track of whether or not the game has been won (set it to False) and an integer variable to keep track of the number of guesses remaining (set it to 4). - This assignment brief will assume variable names of "wordList", "password", "won" and "guessesRemaining" for the variables mentioned above. - The "random.sample()" function can be used to randomly select a number of items from a list, and "random.choice()" can be used to randomly select just one item from a list. - The won variable will be set to True if the password is guessed, and will help to control the loop (see Requirement 2) and decide which message to print at the end of the game (see Requirement 3). 2. Print a message to welcome the user, and then enter a loop that will repeat while guessesRemaining is greater than 0 and won is False. The body of this loop must... Print all of the words in wordList along with their corresponding index number, and then print the number of guesses remaining. - The most efficient way to print all of the words in wordList is to use a "for" loop and the "enumerate()" function. See Lecture 3, Slide 38 for an example of this. Prompt the user to choose one of the words by entering its index number (0-7), and reduce guessesRemaining by 1. - Note that the user inputs an index number, not the word itself. To get the corresponding word, refer to that index number of wordList. - Remember that the "input()" function always returns the user's input as a string - you will need to convert it to an integer before you can use the value as an index number of wordList. Print the selected word, and then check if it is the same as password. If the words are the same, the user has guessed correctly: The program should print a "password correct" message and set the won variable to True. If the words are not the same, the user has guessed incorrectly: Print a "password incorrect" message, then call the "compareWords" function to determine the number of matching letters before printing a message to tell the user how many letters are correct. 3. The last thing the program should do (after the body of the loop described in Requirement 2) is print a "you win" message if the won variable is True, or a "you lose" message if it is False. - By the time the program reaches this point, either the loop ended because the user ran out of guesses (and hence the won variable is still set to False), or because the user guessed correctly (and hence the won variable was set to True as per Requirement 2.3). The "compareWords" function When the user selects a word that is not the password, the program needs to determine how many matching letters there are between the password and the selected word (see Requirement 2.3). Your program must define a function named "compareWords" that receives two words (the password and the selected word) as parameters. It must determine the number of matching letters between the words, and return this number back to the program as an integer. It is up to you to design and implement the code necessary to implement this functionality. The definition of the function should be at the start of the program (as it is in the starter file provided), and it should be called where needed in the program. Revise Module 4 if you are uncertain about defining and using functions, and be sure to implement it so that it receives and returns values exactly as described above. The function should return the number of matching letters - it should not print anything itself.

Programming Logic & Design Comprehensive
9th Edition
ISBN:9781337669405
Author:FARRELL
Publisher:FARRELL
Chapter7: File Handling And Applications
Section: Chapter Questions
Problem 7PE
icon
Related questions
Question

Background Information

This assignment tests your understanding of and ability to apply the programming concepts we have covered in the unit so far, including the usage of variables, input and output, data types, selection, iteration, functions and data structures. Above all else, it tests your ability to design and then implement a solution to a problem using these concepts.

Assignment Overview

You are required to design and implement a "Word Game" program in which the user must identify a randomly selected "password" from a list of 8 words. The 8 words are selected at random from the list of 100 words in the starter file (word_game.py) provided to you with this assignment brief. Please use the starter file as the basis of your assignment code.

The user has 4 attempts in which to guess the password. Whenever they guess incorrectly, they are told how many of the letters are the same between the word they guessed and the password. For example, if the password is "COMEDY" and they guessed "MOULDY", they would be told that 3/6 letters were correct due to the O, D and Y being the same. Note that a letter must be in the correct position to be correct. e.g. In the example above, both words contain the letter "M" but it is in a different position in the word so it is not counted as a correct letter.

Using this information, the user can make increasingly knowledgeable guesses and win the game by selecting the password within four guesses. If the user fails to select the correct word within 4 guesses, they lose the game.

Pseudocode
As emphasised by the case study of Module 5, it is important to take the time to properly design a solution before starting to write code. Hence, this assignment requires you to write and submit pseudocode of your program design as well as the code for the program. Furthermore, while your tutors are happy to provide help and feedback on your assignment work throughout the semester, they will expect you to be able to show your pseudocode and explain the design of your code.

You will gain a lot more benefit from pseudocode if you actually attempt it before trying to code your program - even if you just start with a rough draft to establish the overall program structure, and then revise and refine it as you work on the code. This back and forth cycle of designing and coding is completely normal and expected, particularly when you are new to programming. The requirements detailed on the following pages should give you a good idea of the structure of the program, allowing you to make a start on designing your solution in pseudocode.

Write a separate section of pseudocode for each function you define in your program so that the pseudocode for the main part of your program is not cluttered with function definitions. Ensure that the pseudocode for each of your functions clearly describes the parameters that the function receives and what the function returns back to the program.

It may help to think of the pseudocode of your program as the content of a book, and the pseudocode of functions as its appendices: It should be possible to read and understand a book without necessarily reading the appendices, however they are there for further reference if needed.

Only one function is required in this assignment (detailed later in the assignment brief).

Program Requirements

These requirements begin where the starter file ends - after defining the "candidateWords" list. In the following information, numbered points describe a core requirement of the program, and bullet points (in italics) are additional details, notes and hints regarding the requirement. Ask your tutor if you do not understand a requirement or would like further details.

1. Set up the game by creating a list of 8 randomly selected words from candidateWords and then randomly select one of those words to be the password. Also create a boolean variable to keep track of whether or not the game has been won (set it to False) and an integer variable to keep track of the number of guesses remaining (set it to 4).

- This assignment brief will assume variable names of "wordList", "password", "won" and "guessesRemaining" for the variables mentioned above.
- The "random.sample()" function can be used to randomly select a number of items from a list, and "random.choice()" can be used to randomly select just one item from a list.
- The won variable will be set to True if the password is guessed, and will help to control the loop (see Requirement 2) and decide which message to print at the end of the game (see Requirement 3).

2. Print a message to welcome the user, and then enter a loop that will repeat while
guessesRemaining is greater than 0 and won is False. The body of this loop must...
Print all of the words in wordList along with their corresponding index number, and then print the number of guesses remaining.
- The most efficient way to print all of the words in wordList is to use a "for" loop and the "enumerate()" function. See Lecture 3, Slide 38 for an example of this.
Prompt the user to choose one of the words by entering its index number (0-7), and reduce guessesRemaining by 1.
- Note that the user inputs an index number, not the word itself. To get the corresponding word, refer to that index number of wordList.
- Remember that the "input()" function always returns the user's input as a string - you will
need to convert it to an integer before you can use the value as an index number of wordList.

Print the selected word, and then check if it is the same as password.
If the words are the same, the user has guessed correctly: The program should print a "password correct" message and set the won variable to True.
If the words are not the same, the user has guessed incorrectly: Print a "password incorrect" message, then call the "compareWords" function to determine the number of matching letters before printing a message to tell the user how many letters are correct.

3. The last thing the program should do (after the body of the loop described in Requirement 2) is print a "you win" message if the won variable is True, or a "you lose" message if it is False.
- By the time the program reaches this point, either the loop ended because the user ran out of guesses
(and hence the won variable is still set to False), or because the user guessed correctly (and hence the
won variable was set to True as per Requirement 2.3).

The "compareWords" function
When the user selects a word that is not the password, the program needs to determine how many matching letters there are between the password and the selected word (see Requirement 2.3).

Your program must define a function named "compareWords" that receives two words (the password and the selected word) as parameters. It must determine the number of matching letters between the words, and return this number back to the program as an integer. It is up to you to design and implement the code necessary to implement this functionality.

The definition of the function should be at the start of the program (as it is in the starter file provided), and it should be called where needed in the program. Revise Module 4 if you are uncertain about defining and using functions, and be sure to implement it so that it receives and returns values exactly as described above. The function should return the number of matching letters - it should not print anything itself.

Expert Solution
steps

Step by step

Solved in 5 steps with 2 images

Blurred answer
Knowledge Booster
Graphical User Interface
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr