|
4 | 4 | class OopQuiz(Quiz):
|
5 | 5 | def __init__(self, title=""):
|
6 | 6 | q1 = Question(
|
7 |
| - question="Based on what you learned about Python's special methods, which of the following statements is <strong>true</strong>?", |
| 7 | + question="Based on what you learned about Python's special methods, which statement best describes the relationship between <i>__str__</i> and <i>__repr__</i>?", |
8 | 8 | options={
|
9 |
| - "__repr__ is also used for __str__, but not vice versa.": "Correct! This statement is true.", |
10 |
| - "__str__ is also used for __repr__, but not vice versa.": "The opposite is true.", |
11 |
| - "__repr__ and __str__ are completely independent.": "__repr__ is also used for __str__, but not vice versa.", |
| 9 | + "__repr__ is used as a fallback when __str__ is missing.": "Correct! When __str__ is not defined, Python will use __repr__ instead.", |
| 10 | + "__str__ is used as a fallback when __repr__ is missing.": "Think again based on the example we saw earlier.", |
| 11 | + "__repr__ and __str__ are independent methods with no relationship to each other.": "There is a relationship between the two methods. Which one could it be?", |
12 | 12 | },
|
13 |
| - correct_answer="__repr__ is also used for __str__, but not vice versa.", |
| 13 | + correct_answer="__repr__ is used as a fallback when __str__ is missing.", |
14 | 14 | hint="",
|
15 | 15 | shuffle=True,
|
16 | 16 | )
|
17 | 17 |
|
18 | 18 | q2 = Question(
|
19 | 19 | question="Based on what you learned about Python's comparison methods, which of the following statements is <strong>false</strong>?",
|
20 | 20 | options={
|
21 |
| - "If we implement __gt__, Python will also use it for __lt__": "This statement is true.", |
22 |
| - "If we implement __lt__, Python will also use it for __le__": "Correct! This statement is false.", |
23 |
| - "If we implement __eq__, Python will also use it for __ne__": "This statement is true.", |
| 21 | + "If we implement __gt__, Python will also use it for __lt__": "Wrong! This statement is true because Python is able to cleverly swap the comparison terms.", |
| 22 | + "If we implement __lt__, Python will also use it for __le__": "Correct! This statement is false because Python has no knowledge of what equality could mean based just on a comparison.", |
| 23 | + "If we implement __eq__, Python will also use it for __ne__": "Wrong! This statement is true because Python is able to cleverly negate the equality comparison.", |
24 | 24 | },
|
25 | 25 | correct_answer="If we implement __lt__, Python will also use it for __le__",
|
26 | 26 | hint="",
|
27 | 27 | shuffle=True,
|
28 | 28 | )
|
29 | 29 |
|
30 | 30 | q3 = Question(
|
31 |
| - question="Based on what you learned about the @property keyword, which of the following statements is <strong>false</strong>?", |
| 31 | + question="Based on what you learned about the <i>@property</i> keyword, which of the following statements is <strong>true</strong>?", |
32 | 32 | options={
|
33 |
| - "@property creates attributes that act like methods but can be accessed and assigned as regular attributes.": "This statement is true.", |
34 |
| - "@property helps implement attributes that require additional logic or validation when getting or setting their values.": "This statement is true.", |
35 |
| - "@property makes code more readable but restricts dynamic attibute behaviour.": "Correct! This statement is false.", |
| 33 | + "@property creates attributes that act like methods, which means that they need to be called as regular methods.": "Wrong! This statement is false beacuse we access these attributes as regular ones.", |
| 34 | + "@property helps implement attributes that require additional logic or validation when calculating their values.": "Correct! This is how you can make your classes more readable and user-friendly.", |
| 35 | + "@property allows to get and set the values of attributes, while applying additional logic in the background.": "Wrong! This statement is false beacuse we are not allowed to directly set the values of these attributes.", |
36 | 36 | },
|
37 |
| - correct_answer="@property makes code more readable but restricts dynamic attibute behaviour.", |
| 37 | + correct_answer="@property helps implement attributes that require additional logic or validation when calculating their values.", |
38 | 38 | hint="",
|
39 | 39 | shuffle=True,
|
40 | 40 | )
|
|
0 commit comments