You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/exercises/rock-paper-scissors/instructions.qmd
+67-34Lines changed: 67 additions & 34 deletions
Original file line number
Diff line number
Diff line change
@@ -5,55 +5,72 @@ number-sections: false
5
5
6
6
# "Rock, Paper, Scissors" Game {.unnumbered}
7
7
8
-
Develop a Python application which will allow a human user to play a game of Rock-Paper-Scissors against a computer opponent. The game's functionality should adhere to the "Requirements" section below.
8
+
Develop a Python application which allows a human user to play a game of [Rock Paper Scissors](https://en.wikipedia.org/wiki/Rock_paper_scissors) against a computer opponent. The game's functionality should adhere to the "Requirements" section below.
9
+
9
10
10
-
For this assignment specifically, all game code should exist in a single cell.
11
11
12
12
## Requirements
13
13
14
-
### Welcome Message
14
+
:::{.callout-note title="Note"}
15
+
For this assignment, all game code should exist in a single code cell!
16
+
:::
15
17
16
-
The application should instruct the player via text cell to set their name as a [notebook secret](../../notes/dev-tools/google-colab/notebook-secrets.html#implementation) specifically called `PLAYER_NAME`.
18
+
### Welcome Message
17
19
18
-
Then the application should then read this value from the notebook secrets, and store the value in a Python variable called `player_name`.
20
+
The application should instruct the player via text cell to set their name using a [notebook secret](../../notes/dev-tools/google-colab/notebook-secrets.html#implementation) specifically called `PLAYER_NAME` (using all capital letters).
19
21
20
-
The application should display a friendly message welcoming the user, such as "Welcome Jon, to our Rock Paper Scissors Game!" (for example if "Jon" was set as the player's name).
22
+
The application should read the player name from the notebook secrets, and store the value in a Python variable specifically called `PLAYER_NAME` (using all capital letters).
21
23
22
-
> HINT: adapt the example code relating to `userdata`, provided at the bottom of the notebook secrets menu, but change the variable names.
24
+
The application should display a friendly message welcoming the user, for example: "Welcome Jon, to our Rock Paper Scissors Game!" (if "Jon" was set as the player's name).
23
25
24
26
### Processing User Inputs
25
27
26
28
The application should prompt the user to input, or otherwise select, an option (i.e. "rock", "paper", or "scissors"). It should store the user's selection in a variable for later reference.
27
29
28
-
> HINT: use the [`input` function](../../notes/python-lang/overview.ipynb#the-input-function) to capture user inputs.
30
+
:::{.callout-tip title="Hint" collapse="true"}
31
+
Use the [`input` function](../../notes/python-lang/overview.ipynb#the-input-function), or [form inputs](../../notes/dev-tools/google-colab/form-inputs.ipynb#colab-form-inputs), or [widgets](../../notes/dev-tools/google-colab/form-inputs.ipynb#jupyter-widgets), to capture user inputs. If you use form inputs or widgets, that should also satisfy the validation steps below. [:smile_cat:]{.content-visible when-format="html"}
32
+
:::
33
+
29
34
30
35
### Validating User Inputs
31
36
32
-
The application should compare the user's selection against the list of valid options (i.e. "rock", "paper", "scissors") to determine whether the user has selected a valid option.
37
+
The application should compare the user's selection against the list of valid options (i.e. "rock", "paper", "scissors") to determine whether the user has selected a valid option. See additional validation requirements below.
38
+
39
+
#### Graceful Failure
40
+
41
+
If the selection is invalid, the program should fail gracefully by displaying a friendly message to the user, and preventing further program execution. The program should not try to further process an invalid input, as it may lead to runtime errors. In other words, the program should not move on to generating a computer choice (see "Simulating Computer Selection" section below) unless the user input is valid.
33
42
34
-
**Case Normalization**:
43
+
:::{.callout-tip title="Hint" collapse="true"}
44
+
Check the selection option using [conditional logic](../../notes/python-lang/control-flow/conditional-logic.qmd).
45
+
:::
35
46
36
-
The program should be able to handle various capitalizations of the valid options (e.g. "ROCK", "Rock", "rock", "RoCk", etc. are all valid).
47
+
#### Case Normalization
37
48
38
-
> HINT: use string case manipulation methods on the original user input to simplify your conditional logic
49
+
The program should be able to handle various capitalizations of the valid options (e.g. "ROCK", "Rock", "rock", "RoCk", etc.) Any combination of lowercase and uppercase letters for a given option should be considered valid.
39
50
40
-
**Graceful Failure**:
51
+
:::{.callout-tip title="Hint" collapse="true"}
52
+
Modify the user input value [string case manipulation](../../notes/python-lang/basic-datatypes/strings.qmd#case-manipulation) before checking the selected option.
53
+
:::
41
54
42
-
If the selection is invalid, the program should fail gracefully by displaying a friendly message to the user, and preventing further program execution. The program should not try to further process an invalid input, as it may lead to runtime errors.
55
+
#### Validation Loop
43
56
44
-
**Validation Loop**:
57
+
If the selection is invalid, the program should continue to prompt the user to input a value until the user inputs a valid input.
45
58
46
-
If the selection is invalid, the program should ideally continue to prompt the user to input a value until the user inputs a valid input.
59
+
:::{.callout-tip title="Hint" collapse="true"}
60
+
Ask for an input within the scope of a [`while` loop](../../notes/python-lang/control-flow/while-loops.qmd), and break out of the loop if the selection is valid.
61
+
:::
47
62
48
-
> HINT: ask for an input within the scope of a [`while` loop](../../notes/python-lang/control-flow/while-loops.qmd), and break out of the loop if the selection is valid.
49
63
50
64
### Simulating Computer Selection
51
65
52
66
The application should select one of the options (i.e. "rock", "paper", or "scissors") at random, and assign that as the computer player's choice.
53
67
54
-
> HINT: use the `choice` function provided by [the `random` module](../../notes/python-modules/random.qmd).
68
+
:::{.callout-tip title="Hint" collapse="true"}
69
+
Use the `choice` function provided by [the `random` module](../../notes/python-modules/random.qmd).
70
+
71
+
Ensure the valid choices are stored in a [list datatype](../../notes/python-lang/container-datatypes/lists.qmd), and then pass that list to the random choice function.
72
+
:::
55
73
56
-
> HINT: ensure the valid choices are stored in a [list datatype](../../notes/python-lang/container-datatypes/lists.qmd), and then pass that list to the random choice function.
57
74
58
75
### Determining the Winner
59
76
@@ -64,7 +81,9 @@ The application should compare the user's selection to the computer player's sel
64
81
3. Scissors beats Paper
65
82
4. Rock vs Rock, Paper vs Paper, and Scissors vs Scissors each results in a "tie"
66
83
67
-
> HINT: use one or more [`if` statements](../../notes/python-lang/control-flow/conditional-logic.qmd) (recommended approach for beginners). FYI - it may also be possible to use other pre-configured representations of the winners, for example using a nested [dictionary datatype](../../notes/python-lang/container-datatypes/dictionaries.qmd) containing all possible outcomes.
84
+
:::{.callout-tip title="Hint" collapse="true"}
85
+
Beginners, feel free to use [conditional logic](../../notes/python-lang/control-flow/conditional-logic.qmd).
86
+
:::
68
87
69
88
### Displaying Results
70
89
@@ -73,7 +92,7 @@ After determining the winner, the application should display the results to the
73
92
+ A friendly welcome message, including the player's name (e.g. "Player One").
74
93
+ The user's selected option
75
94
+ The computer's selected option
76
-
+Whether the user or the computer was the winner
95
+
+What the game outcome was (user wins, computer wins, or tie)
77
96
+ A friendly farewell message
78
97
79
98
Example desired output after one round of game-play:
@@ -92,28 +111,42 @@ You won! Thanks for playing.
92
111
93
112
## Evaluation
94
113
95
-
Submissions will be evaluated according to the "Requirements" section, as represented by the following rubric:
114
+
Submissions will be evaluated according to the detailed "Requirements" above, as represented by the following rubric:
96
115
97
116
Category | Requirement | Weight
98
117
--- | --- | ---
99
-
Info Inputs | Prompts the user to input their player name via notebook secrets, and reads the value from notebook secrets. | 10%
100
-
Info Inputs | Prompts the user to input / select a choice from one of "rock", "paper", or "scissors". | 15%
101
-
Validations | Handles user inputs of various capitalization (i.e. recognizes "rock", "Rock", "ROCK", "RoCk", etc. as valid inputs). | 15%
102
-
Validations | Fails gracefully if encountering an invalid user input (i.e. program does not crash or malfunction if user provides an invalid input, like "OOPS"). Avoids a red / crashed cell. | 15%
103
-
Simulation | Generates a valid choice at random for the computer player. | 15%
104
-
Calculations | Displays accurate information about which player is the winner. | 15%
105
-
Info Outputs | Presents all desired information outputs to the user, ideally in a clear way with clean formatting. | 15%
118
+
Info Inputs | Reads the player name from notebook secrets. | 10%
119
+
Info Inputs | Prompts the user to input or select an option. | 15%
120
+
Validations | Handles user inputs of various capitalization. | 15%
121
+
Validations | Fails gracefully if encountering an invalid user input. | 15%
122
+
Simulation | Generates a random computer choice. | 15%
123
+
Calculations | Displays the winner accurately. | 15%
124
+
Info Outputs | Displays all desired information. | 15%
125
+
126
+
: {tbl-colwidths="[25,60,15]"}
106
127
107
128
This rubric is tentative, and may be subject to slight adjustments during the grading process.
108
129
109
130
If experiencing execution error(s) while evaluating the application's required functionality, evaluators are advised to reduce the project's grade by between 4% and 25%, depending on the circumstances and severity of the error(s).
110
131
111
-
### Further Exploration (Game Loop Challenges)
132
+
## Further Exploration
133
+
134
+
### Game Loop Challenges
135
+
136
+
**Play Again**: The application should ask the user whether they'd like to play again. If they say "yes", it should play the game again, otherwise it should stop. The user should be able to continue playing as many games as they want.
137
+
138
+
:::{.callout-tip title="Hint" collapse="true"}
139
+
Use an infinite `while` loop!
140
+
:::
141
+
142
+
**Game Stats**: The application should keep track of how many games have been played, and how many games have been won, and once the user elects to stop playing, it should display their win percentage.
112
143
113
-
+10%: For extra credit, also implement a game loop that asks the user whether they'd like to play again. If they say "yes", play the game again, otherwise stop. The user should be able to play as many games as they want.
144
+
You can count ties as losses, or remove them from the denominator. In other words, either of the following win percentage formulae would be fine:
114
145
115
-
> HINT: use an infinite `while` loop!
146
+
A) $$\text{win percentage} = \frac{\text{wins}}{\text{total games}}$$
116
147
117
-
+10%: For maximum challenge and maximum bonus points, also keep track of how many games have been played, and how many games have been won, and once the user elects to stop playing, display their win percentage.
148
+
B) $$\text{win percentage} = \frac{\text{wins}}{\text{total games} - \text{ties}}$$
118
149
119
-
> HINT: use a counter approach in conjunction with your `while` loop.
150
+
:::{.callout-tip title="Hint" collapse="true"}
151
+
Use a counter approach in conjunction with your `while` loop.
0 commit comments