|
1083 | 1083 | "Each scoop should have a **single** attribute, `flavor`, a string that you can initialize when you create the instance of `Scoop`.\n",
|
1084 | 1084 | "\n",
|
1085 | 1085 | "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", |
1087 | 1087 | "**Pay attention to the single quotes!**\n",
|
1088 | 1088 | "\n",
|
1089 | 1089 | "Modify the `solution_ice_cream_scop` function to return a list of tuples each containing a Scoop instance and its flavor.\n",
|
1090 | 1090 | "The list of flavors will be provided to you as an argument to the function.\n",
|
1091 | 1091 | "\n",
|
1092 | 1092 | "<div class=\"alert alert-block alert-warning\">\n",
|
1093 | 1093 | " <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", |
1095 | 1095 | "</div>"
|
1096 | 1096 | ]
|
1097 | 1097 | },
|
|
1105 | 1105 | "outputs": [],
|
1106 | 1106 | "source": [
|
1107 | 1107 | "%%ipytest\n",
|
| 1108 | + "\n", |
1108 | 1109 | "class Scoop:\n",
|
1109 | 1110 | " \"\"\"A class representing a single scoop of ice cream\"\"\"\n",
|
1110 | 1111 | " # Write your class implementation here\n",
|
| 1112 | + " \n", |
1111 | 1113 | "\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", |
1113 | 1115 | " # Write your solution here\n",
|
1114 |
| - " pass" |
| 1116 | + " return" |
1115 | 1117 | ]
|
1116 | 1118 | },
|
1117 | 1119 | {
|
|
1129 | 1131 | "id": "4244ff19-7bbf-43cc-9d1e-eba13f7f5e4e",
|
1130 | 1132 | "metadata": {},
|
1131 | 1133 | "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", |
1134 | 1135 | "\n",
|
1135 | 1136 | "The `Bowl` class should have a method called `add_scoops()` that accept **variable number** of scoops.\n",
|
1136 | 1137 | "\n",
|
1137 | 1138 | "<div class=\"alert alert-block alert-info\">\n",
|
1138 | 1139 | " <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", |
1140 | 1141 | "</div>\n",
|
1141 | 1142 | "\n",
|
1142 | 1143 | "<div class=\"alert alert-block alert-warning\">\n",
|
1143 | 1144 | " <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>" |
1152 | 1147 | ]
|
1153 | 1148 | },
|
1154 | 1149 | {
|
|
1161 | 1156 | "outputs": [],
|
1162 | 1157 | "source": [
|
1163 | 1158 | "%%ipytest\n",
|
| 1159 | + "\n", |
1164 | 1160 | "class Bowl:\n",
|
1165 | 1161 | " \"\"\"A class representing a bowl of ice cream scoops\"\"\"\n",
|
1166 | 1162 | " # 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", |
1169 | 1166 | " # Write your solution here\n",
|
1170 |
| - " pass" |
| 1167 | + " return" |
1171 | 1168 | ]
|
1172 | 1169 | },
|
1173 | 1170 | {
|
1174 | 1171 | "cell_type": "markdown",
|
1175 | 1172 | "id": "419b5378-ff17-4ed3-8203-97c132918cb7",
|
1176 | 1173 | "metadata": {
|
| 1174 | + "jp-MarkdownHeadingCollapsed": true, |
1177 | 1175 | "tags": []
|
1178 | 1176 | },
|
1179 | 1177 | "source": [
|
|
1293 | 1291 | "cell_type": "markdown",
|
1294 | 1292 | "id": "09ef6028-b6a6-4f79-a418-bce3e3e3f60f",
|
1295 | 1293 | "metadata": {
|
| 1294 | + "jp-MarkdownHeadingCollapsed": true, |
1296 | 1295 | "tags": []
|
1297 | 1296 | },
|
1298 | 1297 | "source": [
|
|
1543 | 1542 | "name": "python",
|
1544 | 1543 | "nbconvert_exporter": "python",
|
1545 | 1544 | "pygments_lexer": "ipython3",
|
1546 |
| - "version": "3.11.1" |
| 1545 | + "version": "3.11.3" |
1547 | 1546 | }
|
1548 | 1547 | },
|
1549 | 1548 | "nbformat": 4,
|
|
0 commit comments