8000 Fixes exercise text and solution skeleton · gaehlerm/python-tutorial@bf21c9c · GitHub
[go: up one dir, main page]

Skip to content

Commit bf21c9c

Browse files
committed
Fixes exercise text and solution skeleton
1 parent ef6724c commit bf21c9c

File tree

2 files changed

+24
-24
lines changed

2 files changed

+24
-24
lines changed

object_oriented_programming.ipynb

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1083,15 +1083,15 @@
10831083
"Each scoop should have a **single** attribute, `flavor`, a string that you can initialize when you create the instance of `Scoop`.\n",
10841084
"\n",
10851085
"Define also a `__str__` method to return a string reprensentation of a scoop.\n",
1086-
"The output should be `Ice cream scoop with flavor '<flavor>'`, where `<flavor` is the actual scoop's flavor.\n",
1086+
"The output should be `Ice cream scoop with flavor '<flavor>'`, where `<flavor>` is the actual scoop's flavor.\n",
10871087
"**Pay attention to the single quotes!**\n",
10881088
"\n",
10891089
"Modify the `solution_ice_cream_scop` function to return a list of tuples each containing a Scoop instance and its flavor.\n",
10901090
"The list of flavors will be provided to you as an argument to the function.\n",
10911091
"\n",
10921092
"<div class=\"alert alert-block alert-warning\">\n",
10931093
" <h4><b>Question</b></h4>\n",
1094-
" Complete the solution function such that it creates <strong>three</strong> instances of the <code>Scoop</code> class with the following flavors: chocolate, vanilla, persimmon. This function should return a list that collects the <strong>string representations</strong> of the ice cream scoops.\n",
1094+
" Complete the solution function to create instances of the <code>Scoop</code> class with the following example flavors: chocolate, vanilla, persimmon. This function should return a <strong>list of tuples</strong> of the kind <code>(Scoop, __str__)</code>, where <code>__str__</code> stands for the <strong>string representations</strong> of the ice cream <code>Scoop</code> instance.\n",
10951095
"</div>"
10961096
]
10971097
},
@@ -1105,13 +1105,15 @@
11051105
"outputs": [],
11061106
"source": [
11071107
"%%ipytest\n",
1108+
"\n",
11081109
"class Scoop:\n",
11091110
" \"\"\"A class representing a single scoop of ice cream\"\"\"\n",
11101111
" # Write your class implementation here\n",
1112+
" \n",
11111113
"\n",
1112-
"def solution_ice_cream_scoop(flavors: tuple[str]) -> list[str]:\n",
1114+
"def solution_ice_cream_scoop(flavors: tuple[str]) -> list[tuple]:\n",
11131115
" # Write your solution here\n",
1114-
" pass"
1116+
" return"
11151117
]
11161118
},
11171119
{
@@ -1129,26 +1131,19 @@
11291131
"id": "4244ff19-7bbf-43cc-9d1e-eba13f7f5e4e",
11301132
"metadata": {},
11311133
"source": [
1132-
"Create a class `Bowl` that can hold many ice cream scoops, as many as you like.\n",
1133-
"You *should use* the custom class you created in the previous exercise.\n",
1134+
"Create a class `Bowl` that can hold many ice cream scoops, as many as you like. You should use the `Scoop` class you created in the previous exercise.\n",
11341135
"\n",
11351136
"The `Bowl` class should have a method called `add_scoops()` that accept **variable number** of scoops.\n",
11361137
"\n",
11371138
"<div class=\"alert alert-block alert-info\">\n",
11381139
" <h4><b>Hint</b></h4>\n",
1139-
" In the <code>__init__</code> method of the <code>Bowl</code> class, you should define an attribute that acts as a container to hold the scoops you might want to add\n",
1140+
" In the <code>__init__</code> method of the <code>Bowl</code> class, you should define an attribute that acts as a container to hold all the scoops you might want to add\n",
11401141
"</div>\n",
11411142
"\n",
11421143
"<div class=\"alert alert-block alert-warning\">\n",
11431144
" <h4><b>Question</b></h4> \n",
1144-
" Complete the solution function that creates a bowl of three scoops with flavors chocolate, vanilla, and stracciatella. The output of this function should be a <strong>string</strong> that reports the content of the bowl just created.\n",
1145-
"</div>\n",
1146-
"\n",
1147-
"For example:\n",
1148-
"\n",
1149-
"```\n",
1150-
"Ice cream bowl with chocolate, vanilla, stracciatella scoops\n",
1151-
"```"
1145+
" Complete the solution function to create a bowl of scoops with flavors chocolate, vanilla, and stracciatella, for example. The function should output a <strong>tuple</strong> containing the <code>Bowl</code> instance and its content (a string). The bowl content should be formatted as follows: <code>Ice cream bowl with chocolate, vanilla, stracciatella scoops</code>\n",
1146+
"</div>"
11521147
]
11531148
},
11541149
{
@@ -1161,19 +1156,22 @@
11611156
"outputs": [],
11621157
"source": [
11631158
"%%ipytest\n",
1159+
"\n",
11641160
"class Bowl:\n",
11651161
" \"\"\"A class representing a bowl of ice cream scoops\"\"\"\n",
11661162
" # Write your class implementation here\n",
1167-
" \n",
1168-
"def solution_ice_cream_bowl(flavors: tuple[str]) -> str:\n",
1163+
"\n",
1164+
"\n",
1165+
"def solution_ice_cream_bowl(flavors: tuple[str]) -> tuple[object, str]:\n",
11691166
" # Write your solution here\n",
1170-
" pass"
1167+
" return"
11711168
]
11721169
},
11731170
{
11741171
"cell_type": "markdown",
11751172
"id": "419b5378-ff17-4ed3-8203-97c132918cb7",
11761173
"metadata": {
1174+
"jp-MarkdownHeadingCollapsed": true,
11771175
"tags": []
11781176
},
11791177
"source": [
@@ -1293,6 +1291,7 @@
12931291
"cell_type": "markdown",
12941292
"id": "09ef6028-b6a6-4f79-a418-bce3e3e3f60f",
12951293
"metadata": {
1294+
"jp-MarkdownHeadingCollapsed": true,
12961295
"tags": []
12971296
},
12981297
"source": [
@@ -1543,7 +1542,7 @@
15431542
"name": "python",
15441543
"nbconvert_exporter": "python",
15451544
"pygments_lexer": "ipython3",
1546-
"version": "3.11.1"
1545+
"version": "3.11.3"
15471546
}
15481547
},
15491548
"nbformat": 4,

tutorial/tests/test_object_oriented_programming.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,12 @@
77

88

99
FLAVORS = [
10-
(),
11-
("chocolate"),
10+
("chocolate",),
1211
("chocolate", "vanilla", "persimmon"),
1312
("chocolate", "vanilla", "stracciatella"),
1413
("chocolate", "vanilla", "stracciatella", "strawberry"),
1514
("chocolate", "vanilla", "stracciatella", "strawberry", "pistachio"),
16-
]
15+
]
1716

1817
#
1918
# Exercise 1: Ice cream scoop
@@ -29,9 +28,11 @@ def __init__(self, flavor: str):
2928
def __str__(self):
3029
return f"Ice cream scoop with flavor '{self.flavor}'"
3130

31+
3232
def reference_ice_cream_scoop(flavors: tuple[str]) -> list[Scoop, str]:
3333
return [(Scoop(flavor), str(Scoop(flavor))) for flavor in flavors]
3434

35+
3536
@pytest.mark.parametrize("flavors", FLAVORS)
3637
def test_ice_cream_scoop(flavors, function_to_test) -> None:
3738
test_solution = [string for _, string in function_to_test(flavors)]
@@ -75,7 +76,7 @@ def read_data(name: str, data_dir: str = "data") -> pathlib.Path:
7576
"""Read input data"""
7677
current_module = sys.modules[__name__]
7778
return (
78-
pathlib.Path(current_module.__file__).parent / f"{data_dir}/{name}"
79+
pathlib.Path(current_module.__file__).parent / f"{data_dir}/{name}"
7980
).resolve()
8081

8182

@@ -185,7 +186,7 @@ def __init__(self, universe_start: str) -> None:
185186
def evolve(self) -> "Universe":
186187
"""Evolve the universe"""
187188
for n, moon_i in enumerate(self.moons[:-1]):
188-
for moon_j in self.moons[n + 1:]:
189+
for moon_j in self.moons[n + 1 :]:
189190
moon_i.update_velocities(moon_j)
190191

191192
for moon in self.moons:

0 commit comments

Comments
 (0)
0