-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Expand OOP introductory notebook (#213)
Co-authored-by: despadam <[email protected]> Co-authored-by: Edoardo Baldi <[email protected]>
- Loading branch information
1 parent
823c146
commit ffbc6c8
Showing
3 changed files
with
363 additions
and
150 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
from .common import Question, Quiz | ||
|
||
|
||
class OopQuiz(Quiz): | ||
def __init__(self, title=""): | ||
q1 = Question( | ||
question="Based on what you learned about Python's special methods, which of the following statements is <strong>true</strong>?", | ||
options={ | ||
"__repr__ is also used for __str__, but not vice versa.": "Correct! This statement is true.", | ||
"__str__ is also used for __repr__, but not vice versa.": "The opposite is true.", | ||
"__repr__ and __str__ are completely independent.": "__repr__ is also used for __str__, but not vice versa.", | ||
}, | ||
correct_answer="__repr__ is also used for __str__, but not vice versa.", | ||
hint="", | ||
shuffle=True, | ||
) | ||
|
||
q2 = Question( | ||
question="Based on what you learned about Python's comparison methods, which of the following statements is <strong>false</strong>?", | ||
options={ | ||
"If we implement __gt__, Python will also use it for __lt__": "This statement is true.", | ||
"If we implement __lt__, Python will also use it for __le__": "Correct! This statement is false.", | ||
"If we implement __eq__, Python will also use it for __ne__": "This statement is true.", | ||
}, | ||
correct_answer="If we implement __lt__, Python will also use it for __le__", | ||
hint="", | ||
shuffle=True, | ||
) | ||
|
||
q3 = Question( | ||
question="Based on what you learned about the @property keyword, which of the following statements is <strong>false</strong>?", | ||
options={ | ||
"@property creates attributes that act like methods but can be accessed and assigned as regular attributes.": "This statement is true.", | ||
"@property helps implement attributes that require additional logic or validation when getting or setting their values.": "This statement is true.", | ||
"@property makes code more readable but restricts dynamic attibute behaviour.": "Correct! This statement is false.", | ||
}, | ||
correct_answer="@property makes code more readable but restricts dynamic attibute behaviour.", | ||
hint="", | ||
shuffle=True, | ||
) | ||
|
||
super().__init__(questions=[q1, q2, q3]) |
Oops, something went wrong.