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
Replace "Eye Color" exercise with "Triathlete" (#359)
* Replace eye-color exercise with triathlete
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
---------
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
"In this exercise, we will implement the following simplified theory on how to predict a child's eye color, based on the eye color of its parents.\n",
499
+
"A triathlon is a race consisting of three disciplines: **swimming**, **cycling**, and **running**, completed back-to-back.\n",
500
500
"\n",
501
-
"We assume that the only existing eye colors are <span style=\"color:blue\">blue</span> and <span style=\"color:brown\">brown</span>. We also assume the following rules:\n",
502
-
"- If both parents have <span style=\"color:brown\">brown</span> eyes, their child will also have <span style=\"color:brown\">brown</span> eyes.\n",
503
-
"- If both parents have <span style=\"color:blue\">blue</span> eyes, their child will also have <span style=\"color:blue\">blue</span> eyes.\n",
504
-
"- If one parent has <span style=\"color:brown\">brown</span> eyes and the other one has <span style=\"color:blue\">blue</span> eyes, the dominant color will be <span style=\"color:brown\">brown</span>.\n",
501
+
"We model this using the following class hierarchy:\n",
502
+
"- **Swimmer** with attribute `swim_time`.\n",
503
+
"- **Cyclist** with attribute `bike_time`.\n",
504
+
"- **Runner** with attribute `run_time`.\n",
505
+
"- **Triathlete** with attributes `name` and `total_time`, which is the sum of all three split times inherited from `Swimmer`, `Cyclist`, and `Runner`.\n",
" <li>Complete the solution function such that it defines classes <strong>Mother</strong> and <strong>Father</strong>, each with an attribute for the eye color.</li>\n",
510
-
" <li>Define class <strong>Child</strong>, which inherits from <strong>Mother</strong> and <strong>Father</strong> and has an attribute called <strong>eye_color</strong>.\n",
511
-
" Then, based on the eye colors of the parents, calculate the child's eye color, according to the rules above and assign it to the attribute <code>eye_color</code>.</li>\n",
512
-
" <li>Create an instance of <strong>Child</strong>, which is being initialized by using the arguments passed in the solution function, namely the eye colors of its parents. Lastly, return this instance.</li>\n",
510
+
" <li>Define the four classes described above.</li>\n",
511
+
" <li>Create and return an instance of <code>Triathlete</code> using the arguments passed to the solution function.</li>\n",
question="Which decorator is used to define a method that does not access the class or instance?",
127
127
options={
128
128
"@staticmethod": "Correct! A static method does not access the class or instance.",
129
-
"@classmethod": "Incorrect. A class method accesses the class using `cls`.",
130
-
"@property": "Incorrect. The `@property` decorator is used to define getter methods.",
131
-
"@abstractmethod": "Incorrect. The `@abstractmethod` decorator is used in abstract classes.",
129
+
"@classmethod": "Incorrect. A class method accesses the class using <code>cls</code>.",
130
+
"@property": "Incorrect. The <code>@property</code> decorator is used to define getter methods.",
131
+
"@abstractmethod": "Incorrect. The <code>@abstractmethod</code> decorator is used in abstract classes.",
132
132
},
133
133
correct_answer="@staticmethod",
134
134
hint="This method is often used for utility functions.",
135
135
shuffle=True,
136
136
)
137
137
138
138
q4=Question(
139
-
question="A method with which decorator takes `cls` as its first parameter?",
139
+
question="A method with which decorator takes <code>cls</code> as its first parameter?",
140
140
options={
141
-
"@classmethod": "Correct! A class method is bound to a class rather than its instances and the parameter `cls` represents the class itself.",
142
-
"@staticmethod": "A static method does not have access to `cls` or `self` and cannot modify the class state.",
141
+
"@classmethod": "Correct! A class method is bound to a class rather than its instances and the parameter <code>cls</code> represents the class itself.",
142
+
"@staticmethod": "A static method does not have access to <code>cls</code> or <code>self</code> and cannot modify the class state.",
143
143
"@abstractmethod": "This decorator defines a method in an abstract class that **must** be implemented by all its concrete subclasses.",
question="What is the purpose of the `@classmethod` decorator?",
151
+
question="What is the purpose of the <code>@classmethod</code> decorator?",
152
152
options={
153
-
"To define a method that belongs to the class rather than an instance": "Correct! A class method belongs to the class and takes `cls` as its first parameter.",
153
+
"To define a method that belongs to the class rather than an instance": "Correct! A class method belongs to the class and takes <code>cls</code> as its first parameter.",
154
154
"To define a method that does not access the class or instance": "Incorrect. This describes a static method.",
155
-
"To define a computed attribute": "Incorrect. Computed attributes are defined using the `@property` decorator.",
156
-
"To define an abstract method": "Incorrect. Abstract methods are defined using the `@abstractmethod` decorator.",
155
+
"To define a computed attribute": "Incorrect. Computed attributes are defined using the <code>@property</code> decorator.",
156
+
"To define an abstract method": "Incorrect. Abstract methods are defined using the <code>@abstractmethod</code> decorator.",
157
157
},
158
158
correct_answer="To define a method that belongs to the class rather than an instance",
159
-
hint="This method takes `cls` as its first parameter.",
159
+
hint="This method takes <code>cls</code> as its first parameter.",
160
160
shuffle=True,
161
161
)
162
162
163
163
q6=Question(
164
-
question="What is the difference between `@staticmethod` and `@classmethod`?",
164
+
question="What is the difference between <code>@staticmethod</code> and <code>@classmethod</code>?",
165
165
options={
166
-
"`@staticmethod` does not access the class or instance, while `@classmethod` takes `cls` as its first parameter": "Correct! This is the key difference between the two decorators.",
167
-
"`@staticmethod` is used for utility functions, while `@classmethod` is used for abstract methods": "Incorrect. Abstract methods are unrelated to these decorators.",
168
-
"`@staticmethod` is faster than `@classmethod`": "Incorrect. Performance is not the defining difference.",
169
-
"`@staticmethod` is used for computed attributes, while `@classmethod` is used for class-level attributes": "Incorrect. Computed attributes are defined using `@property`.",
166
+
"<code>@staticmethod</code> does not access the class or instance, while <code>@classmethod</code> takes <code>cls</code> as its first parameter": "Correct! This is the key difference between the two decorators.",
167
+
"<code>@staticmethod</code> is used for utility functions, while <code>@classmethod</code> is used for abstract methods": "Incorrect. Abstract methods are unrelated to these decorators.",
168
+
"<code>@staticmethod</code> is faster than <code>@classmethod</code>": "Incorrect. Performance is not the defining difference.",
169
+
"<code>@staticmethod</code> is used for computed attributes, while <code>@classmethod</code> is used for class-level attributes": "Incorrect. Computed attributes are defined using <code>@property</code>.",
170
170
},
171
-
correct_answer="`@staticmethod` does not access the class or instance, while `@classmethod` takes `cls` as its first parameter",
171
+
correct_answer="<code>@staticmethod</code> does not access the class or instance, while <code>@classmethod</code> takes <code>cls</code> as its first parameter",
172
172
hint="Think about the parameters each decorator uses.",
173
173
shuffle=True,
174
174
)
@@ -207,9 +207,9 @@ def __init__(self, title=""):
207
207
question="What is the purpose of encapsulation in OOP?",
208
208
options={
209
209
"To bundle data and methods into a single unit": "Correct! Encapsulation bundles data and methods into a single unit.",
210
-
"To define abstract methods": "Incorrect. Abstract methods are defined using the `abc` module.",
210
+
"To define abstract methods": "Incorrect. Abstract methods are defined using the <code>abc</code> module.",
211
211
"To create a class that cannot be inherited": "Incorrect. Encapsulation does not restrict inheritance.",
212
-
"To define static methods": "Incorrect. Static methods are defined using the `@staticmethod` decorator.",
212
+
"To define static methods": "Incorrect. Static methods are defined using the <code>@staticmethod</code> decorator.",
213
213
},
214
214
correct_answer="To bundle data and methods into a single unit",
215
215
hint="Encapsulation is one of the fundamental principles of OOP.",
0 commit comments