代写 game python CS 177

CS 177
Fall 2019
Important Information:
Project #1
This is an individual assignment for you to complete on your own. If you need help, take advantage of the Piazza discussion board, office hours or the open forum lab. You may not work with or assist any another student or receive assistance from anyone outside the CS 177 teaching staff.
Due Date:
Submit your finished program to the Project 1 assignment by 11:59 pm, Sunday September 29th
Problem Description: The “Guess Master” Game
Guess Master is a text-based game where the player is presented with a 4-6 letter secret word and has 10 chances (one character at a time) to guess it. The secret words are randomly selected from a data file containing over 1,200 unique values.
The program starts by displaying a welcome message and prompting the user to press ENTER to continue. At the start of the game, a placeholder is displayed which indicates how many characters are in the secret word and the user is prompted to guess a character. It doesn’t matter if the player guesses with lower- or upper-case characters.
After each guess, if the character entered is a part of the secret word the appropriate spaces in the placeholder are updated to show their positions. (See Figure 1)
During gameplay, the program indicates the current guess number and the characters that have been guessed correctly. The game ends when either the player uses all 10 guesses or all the characters in the secret word have been revealed successfully.
Figure 1 – Example Game Play
Page 1 of 5

CS 177 Fall 2019
Examples of Gameplay
Use the following examples as a reference when testing your project1.py Python program.
Page 2 of 5

CS 177 Fall 2019
Getting Started
There are several components to the Project 1 assignment, including reading data from a file, using the random library and manipulating multiple data types like Integers, Strings and Lists. In addition, it will require you to format and control the display of Strings. The project is broken down into six parts as described below.
Note that all Python commands must be contained within a function.
Part1: Setupyourproject1.pyPythonfile
Start a new Python program named project1.py that includes a header including your name, the program name and a short description of the program’s function. As you write your program, start with pseudo code for each step within the functions. This will allow you to document your program with comments as you work. Your Python program must be clearly commented to receive full credit for the assignment.
Part2: Thewelcome()function
It’s always a good idea to describe a program’s functionality and purpose.
Write a function named welcome() that accepts no arguments and returns no values. This function should complete the following tasks:
• Display a greeting and description of the program’s purpose
• Prompt the user to press the
ENTER key to continue
Part3: Thepick()function
Included with the Project 1 assignment
is a data file named words.txt that contains thousands of 4-6 letter words. Your project1.py program must read these words from the data file and randomly select one for the player to guess.
Write a function named pick()that accepts no arguments and returns a String containing a randomly selected word from the words.txt file. This function should perform the following tasks:
• Open the words.txt data file
• Read the words from the file
• Close the data file
• Randomly choose one word
• Return the chosen word
Hint: Remove the new line character ‘\n’ from the end of the selected word
Example output displayed by the welcome() function
Page 3 of 5

CS 177 Fall 2019
Part4: Theguess()function
Write a function named guess() that accepts three arguments (a guessed character, the secret word and the placeholder) and returns the updated placeholder String. The guess() function will complete the following tasks:
• Define a loop repeating the length of the secret word
o Ifacharacteratthesecretword’scurrentindexmatchesthecharacterguessed
§ Replace the current placeholder String’s character with the guess
• Return the updated placeholder String
Part5: Theplay()function
Write a function named play() that accepts one argument (the secret word) and returns either True or False. The argument accepted by the play() function should be the String containing the word selected from the data file. The function should return True if the player successfully guesses the word and False otherwise. The play() function should perform the following tasks:
• Initialize any necessary variables, including a placeholder String based on the length of the secret word
• Define a loop that repeats 10 times
o DisplaytheplaceholderString
o Prompttheplayerforalettertoguess
o Iftheguessisasinglecharacter,calltheguess()functionprovidingthe
guessed character as the argument
o Iftheguessismorethanonecharacter,displaythemessage:
“Single characters only”
o Ifallthecharactersinthewordhavebeenguessedcorrectly,returnTrue
• After the loop completes, return False
Note: With this structure, the play() function will only return False if it completes 10 loops.
Part6: Themain()function
Your project1.py program needs a function to bring all the program pieces together. Write a function named main() that accepts no arguments and returns no values. It should have the following structure:
• Call the welcome() function to display the message
• Call the pick() function to select a word from the data file
• Call the play() function to start the game
• Display the selected word
• Depending on the results of the game, display the appropriate message
Page 4 of 5

CS 177 Fall 2019
Submit to Blackboard
Submit your finished project1.py Python program to the Project 1 assignment on
Blackboard by the due date: 11:59 pm, Sunday September 29th Project 1 Grading Rubric
Points
Functions Only – All code is contained within functions Part 1 – Setup the project1.py Program File:
Program has correct filename and includes header as specified
Program is fully commented
Part 2 – The welcome() function
welcome() function accepts no arguments and returns no values welcome() displays message describing program functionality welcome() prompts user to press ENTER to start the game
Part 3 – The pick() function
pick() function accepts no arguments and returns a String pick() opens the words.txt data file
pick() reads all data from the file
pick() closes the data file
pick() randomly chooses one word
pick() returns the chosen word
Part 4 – The guess() function
guess() accepts three arguments and returns a String
guess() includes a for loop based on the length of the secret word guess() compares each secret word character to the guess guess() updates the placeholder if the guess is correct
guess() returns the updated placeholder String
Part 5 – The play() function
play() accepts one argument and returns either True or False play() is defined and operates as specified
Part 6 – The main() function
main() accepts no arguments and returns no values main() is defined and operates as specified
Style / Format – Python code is formatted and easy to understand
10
10 10
5 10 5
5
5 10 5 10 5
5 10 10 10 5
5 30
5 20 10
Total Points
200
Page 5 of 5