Skip to content

Commit bdbe4bb

Browse files
authored
Exercises and Projects (#33)
* Exercises, RPS Assignment * Hints Mode * Emojis
1 parent 2814c8e commit bdbe4bb

6 files changed

Lines changed: 134 additions & 78 deletions

File tree

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,12 @@ docs/_build
1212
**/**/*.html
1313
site_libs
1414

15+
# keep includes html files:
16+
!docs/includes/*.html
17+
1518
# pdf generation artifacts:
1619
index.aux
1720
index.log
1821
index.pdf
1922
index.toc
23+
index.tex

docs/_quarto.yml

Lines changed: 29 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -46,23 +46,26 @@ book:
4646
location: sidebar # navbar, sidebar
4747
#type: textbox # overlay, textbox
4848

49-
#navbar:
50-
# right:
51-
# - href: exercises/index.qmd
52-
# text: "Exercises, Assignments, and Projects"
53-
# - about-author.qmd
49+
reader-mode: true
50+
51+
bread-crumbs: true
52+
53+
# top nav (need all these links to also be hidden chapters):
54+
navbar:
55+
right:
56+
- text: "Exercises"
57+
href: exercises/index.qmd
58+
59+
- text: "Projects"
60+
menu:
61+
- exercises/rock-paper-scissors/instructions.qmd
62+
63+
- about-author.qmd
5464

5565
# https://quarto.org/docs/websites/website-navigation.html#side-navigation
5666
sidebar:
5767
logo: images/python-banner-2025.png
5868

59-
#page-footer:
60-
# left: |
61-
# Copyright 2024, <a href="https://prof-rossetti.org/">Michael J Rossetti</a>
62-
# right: |
63-
# This book was built with <a href="https://quarto.org/">Quarto</a>.
64-
65-
6669

6770
chapters:
6871
- index.qmd
@@ -181,16 +184,13 @@ book:
181184
#- href: notes/api-integrations/drinks.ipynb
182185

183186

184-
185-
#- "-----------------"
186-
##- exercises/index.qmd
187-
#- part: "Assignments and Projects"
188-
# #href: exercises/index.qmd
189-
# chapters:
190-
# - exercises/rock-paper-scissors/instructions.qmd
191-
192-
193187
- "-----------------"
188+
- exercises/index.qmd
189+
- part: "Projects"
190+
chapters:
191+
- exercises/rock-paper-scissors/instructions.qmd
192+
- "-----------------"
193+
194194
- about-author.qmd
195195
- "-----------------"
196196

@@ -256,9 +256,9 @@ format:
256256
html:
257257
# https://quarto.org/docs/output-formats/html-themes.html
258258
# https://bootswatch.com/
259-
theme: cosmo
260-
#light: default #flatly
261-
#dark: darkly
259+
theme: #cosmo
260+
light: cosmo # default #flatly
261+
dark: cyborg # vapor # superhero # darkly
262262
css: styles/my-style.css
263263
code-copy: true
264264
#code-fold: false #show
@@ -271,18 +271,13 @@ format:
271271
##number-sections: false
272272
##number-depth: 1
273273

274+
# show emojis :smile:
275+
from: markdown+emoji
276+
274277
# https://quarto.org/docs/reference/formats/html.html#includes
275278
include-in-header:
276-
text: |
277-
<!-- Google tag (gtag.js) -->
278-
<script async src="https://www.googletagmanager.com/gtag/js?id=G-B1MPHWM8NN"></script>
279-
<script>
280-
window.dataLayer = window.dataLayer || [];
281-
function gtag(){dataLayer.push(arguments);}
282-
gtag('js', new Date());
283-
284-
gtag('config', 'G-B1MPHWM8NN');
285-
</script>
279+
- includes/google_analytics.html
280+
- includes/expand_hints.html
286281

287282
pdf:
288283

docs/exercises/index.qmd

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
1-
# Exercises, Assignments, and Projects {.unnumbered}
2-
3-
## Practice Exercises
1+
# Exercises {.unnumbered}
42

53
+ My First Notebook
6-
+ Class 2 Exercises
7-
+ Class 3 Exercises
8-
9-
10-
## Assignments
11-
12-
+ ["Rock, Paper, Scissors" Assignment](../exercises/rock-paper-scissors/instructions.qmd)
4+
+ [Unit 1 Notes and Exercises - Python Language Overview](https://colab.research.google.com/drive/1vvvyyJ5dm6L0BPTr9gKvDL6Xkeyz81ih?usp=sharing) (Summer 2025)
5+
+ [Unit 2 Notes and Exercises - Control Flow](https://colab.research.google.com/drive/1YgWAD0badO8gBVPVs-RuMkGQ5axP8esC?usp=sharing) (Summer 2025)
6+
+ Unit 3 Notes and Exercises - Data Processing (Summer 2025)

docs/exercises/rock-paper-scissors/instructions.qmd

Lines changed: 67 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -5,55 +5,72 @@ number-sections: false
55

66
# "Rock, Paper, Scissors" Game {.unnumbered}
77

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+
910

10-
For this assignment specifically, all game code should exist in a single cell.
1111

1212
## Requirements
1313

14-
### Welcome Message
14+
:::{.callout-note title="Note"}
15+
For this assignment, all game code should exist in a single code cell!
16+
:::
1517

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
1719

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).
1921

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).
2123

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).
2325

2426
### Processing User Inputs
2527

2628
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.
2729

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+
2934

3035
### Validating User Inputs
3136

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.
3342

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+
:::
3546

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
3748

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.
3950

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+
:::
4154

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
4356

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.
4558

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+
:::
4762

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.
4963

5064
### Simulating Computer Selection
5165

5266
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.
5367

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+
:::
5573

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.
5774

5875
### Determining the Winner
5976

@@ -64,7 +81,9 @@ The application should compare the user's selection to the computer player's sel
6481
3. Scissors beats Paper
6582
4. Rock vs Rock, Paper vs Paper, and Scissors vs Scissors each results in a "tie"
6683

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+
:::
6887

6988
### Displaying Results
7089

@@ -73,7 +92,7 @@ After determining the winner, the application should display the results to the
7392
+ A friendly welcome message, including the player's name (e.g. "Player One").
7493
+ The user's selected option
7594
+ 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)
7796
+ A friendly farewell message
7897

7998
Example desired output after one round of game-play:
@@ -92,28 +111,42 @@ You won! Thanks for playing.
92111

93112
## Evaluation
94113

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:
96115

97116
Category | Requirement | Weight
98117
--- | --- | ---
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]"}
106127

107128
This rubric is tentative, and may be subject to slight adjustments during the grading process.
108129

109130
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).
110131

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.
112143

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:
114145

115-
> HINT: use an infinite `while` loop!
146+
A) $$\text{win percentage} = \frac{\text{wins}}{\text{total games}}$$
116147

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}}$$
118149

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.
152+
:::

docs/includes/expand_hints.html

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
2+
<script type="text/javascript">
3+
4+
console.log("EXPAND HINTS with: ?hints=true")
5+
6+
document.addEventListener("DOMContentLoaded", () => {
7+
8+
HINTS_MODE = window.location.href.includes("hint")
9+
if (HINTS_MODE){
10+
document.querySelectorAll(".callout-header").forEach(callout => {
11+
callout.classList.add("collapsed");
12+
13+
let content = callout.parentElement.querySelector(".collapse");
14+
if (content) {
15+
content.classList.add("show");
16+
}
17+
});
18+
}
19+
});
20+
21+
</script>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<!-- Google tag (gtag.js) -->
2+
<script async src="https://www.googletagmanager.com/gtag/js?id=G-B1MPHWM8NN"></script>
3+
<script>
4+
window.dataLayer = window.dataLayer || [];
5+
function gtag(){dataLayer.push(arguments);}
6+
gtag('js', new Date());
7+
8+
gtag('config', 'G-B1MPHWM8NN');
9+
</script>

0 commit comments

Comments
 (0)