代写Project #3 – Converting a Flowchart into Python代做留学生Python程序
- 首页 >> C/C++编程Project #3 – Converting a Flowchart into Python
At the end of this document is a flowchart (Control Flow Diagram) for an implementation of the game hangman. Using that and some starter code, get a version of the game running!
Your Task
Your task is to convert the flowchart for that process into an exactly equivalent running Python 3 program. You will use some starter code to begin the process. Part of this assignment is to test how precisely you can follow the directions below. Another part is that this project DOES NOT HAVE AN AUTOGRADER. You must test your program yourself, and be confident that every piece works as intended. You will still be able to submit as many times as you want before the due date, but gradescope will provide no feedback.
Hangman is a classic child’s word guessing game. One person thinks of a word, and then writes a number of dashes corresponding to the letters in the word. A second person (the player) guesses a single letter. If the letter is in the word, the corresponding dashes are replaced by that letter. The player can only guess 6 letters that aren’t in the word before the game ends and they lose. If all the dashes get replaced by their letter the player wins. Whenever a letter is guessed it gets written down so the player doesn’t guess it again.
The green-shaded rectangle represents the extent of a loop, you will have to identify branches using the skills we learned in class. You will have to figure out how to construct the loop and the branches in Python. There are some boxes with exact python code you must copy in, and there are sections that are more ambiguous, where you are expected to create code that matches described functionality. A more digestible version of the flowchart, with extra explanations can be found here: Hangman Control flow
You are not allowed to omit any code represented by action boxes in the flowchart (although you won’t write anything for the START or END boxes).
STARTER CODE: https://drive.google.com/starter_code
You will be penalized if the statements in the program don't work in the same general way as the flowchart, even if the program works correctly otherwise.
You must include a comment at the designated spot of your program containing your name, “Project #3”, and the date you turn it in.
Save your program as Project3.py
High Quality flowchart download: Hangman Flowchart.pdf
Slides version on the flowchart: Hangman Control flow
Update Board Instructions
You'll notice a section in the flowchart, a rather abstract "update board" box. Here are the detailed instructions on how to complete this process.
We have three variables to keep track of here.
board: which is a list of strings, each string is only one character
long. The character is either a letter if they've guessed that
letter correctly, or a '_' if it hasn't been guessed yet.
c: which is holding the current guess, which will be a string.
secret_word: A single string, the word the player is trying to guess.
The goal here is as follows: The player correctly guesses the letter c, we want to remove all the '_' in board that line up with c in secret_word.
For example, let's say secret_word is 'jazz', the player has correctly guessed 'a'. The variables looks like this before the update:
|
0 |
1 |
2 |
3 |
|
|
|
board |
'_' |
'_' |
'_' |
'_' |
|
c |
'a' |
secret_word |
j |
a |
z |
z |
|
|
|
To update the board, we have to loop through the indices of secret_word. At each index, we need to ask if c == secret_word[index].
If that is True, we need to replace board[index] with the guess c. This replaces the underscore with the correctly guessed letter, we continue on with the loop to replace every spot of c in secret_word with the correct spot in board!
If it is False, we need to look at the next index. This loop can be done with a For or While structure.
|
0 |
1 |
2 |
3 |
board |
'_' |
'a' |
'_' |
'_' |
secret_word |
j |
a |
z |
z |
The flowchart to the right, describes one such solution to this problem.
Testing
Test your program completely. Run it several times: try to break it in any way you can come up with. Once you find a way in which it breaks, try to fix it.
Several recommendations for the testing process:
1. FOR TESTING: You can change the line: secret_word = get_random_word() To something like: secret_word = "hello"a. Now you don't have to figure out the random word. Make sure to change this back before you submit.
2. If something is going wrong, try to add descriptive print statements throughout your code: Something like: print("Inside Loop") or print("Inside Branch 3"),a. You could print out certain variables like print(board), so you can understand what the values are at certain parts of your program
3. You could also try adding some breakpoints to your code and using the built-in VSCode debugger (Debugging Python with Visual Studio Code (VSCode))
4. You could use python tutor to better visualize the objects in the program: https://pythontutor.com/visualize.html#mode=edit
Extra Credit
You may do any, all, or none of these. You will not be penalized, but you won’t get any extra credit, if you attempt an extra credit and it doesn’t work correctly.
Extra Credit #1
Currently our program allows the user to input anything as a guess, and not just a single letter. We should modify our code, so if they try and type anything longer than a single character the guess is not taken, and we let them try again. Players should not lose a turn when this happens. Additionally, the user should not be allowed to guess anything other than a letter. (There is a useful string function that allows us to handle that).
Extra Credit #2
Currently when the game ends, either by the player correctly guessing the word or by running out of guesses, our program ends. We could modify our main method so that when the game ends, a new word is chosen, a new board is created, and the game can be played again. To get the full points for the extra credit you should have your program replay the game an infinite number of times.
Extra Credit #3
Currently the guess history list is in the order that the user has entered their guesses. It would be nicer if we printed their guess history in alphabetical order. This can be done correctly at multiple points in your code (meaning you can sort it when a new guess is added to the list, or you can sort the whole list before you print it, ect). (there is a useful list method that could help here)
Submission
When you are done, turn in the assignment via Gradescope, you should submit only your .py file. It must be named Project3.py. After you submit, no autograder will run to give you feedback. Make sure you have tested your program fully before the due date. After submitting your program, you can still edit your code and resubmit as many times as you want.
Grading
In the report of your grade, you will see a score and a set of letter codes explaining what you did wrong. If you get 10 points, there will be no associated letter codes.
The grading codes A-G are defined and will be the same for all programs that you turn in. A summary of those codes is as follows (see the linked document for a full explanation):
A: -10 Student’s name is missing from the top of the program.
B: -100 Program cannot run due to syntax errors.
C: -75 Program crashes before finishing.
D: -10 (each) Program runs to completion but does not solve all of the assigned problems.
E: -15 (once) Program uses overly advanced methods not covered in class
F: -25 (once) Program works correctly, but changes the assignment in order to do it.
In addition, penalties for this assignment only will be incurred for the following infractions (which may supersede some of the generic codes listed above):
H: -10 Solution deviates too far from the designated flowchart
J: -10 Required code is omitted (like omitting a Print statement, for example, either in part or in its entirety).
K: -10 Steps of the flowchart are implemented out-of-order in the program, even if the program still works correctly.
L: -10 Python shortcuts and/or advanced code is used. This supersedes code F above.
Each of the three extra credit items are worth +3.33 points added to the score only if implemented correctly. Incorrect implementation will not be penalized.