Update page 'Day 3 homework'
+5
-2
@@ -26,7 +26,10 @@ class BoundedInt():
|
|||||||
2. Modify the template to pass test 1, which checks that `int()` called on your class will return the value of `i`.
|
2. Modify the template to pass test 1, which checks that `int()` called on your class will return the value of `i`.
|
||||||
3. Read this, and the paragraph below it: https://docs.python.org/3/reference/datamodel.html?highlight=__int__#object.__add__
|
3. Read this, and the paragraph below it: https://docs.python.org/3/reference/datamodel.html?highlight=__int__#object.__add__
|
||||||
4. What do you think the types of x and y are? Guess, without checking first. What are they, actually? You can use the debugger's local window to find out.
|
4. What do you think the types of x and y are? Guess, without checking first. What are they, actually? You can use the debugger's local window to find out.
|
||||||
5. Modify the template to pass test 2, which checks that:
|
5. Don't forget that you can access the value of a BoundedInt by using either `.i` on it, or `int()`, now that you've passed test 1.
|
||||||
|
6. Modify the template to pass test 2, which checks that:
|
||||||
* Your class implements the + operator.
|
* Your class implements the + operator.
|
||||||
* It throws ValueError when attempting to add two BoundedInts that will exceed the limits.
|
* It throws ValueError when attempting to add two BoundedInts that will exceed the limits.
|
||||||
6. Do the same as 2, but for subtraction.
|
7. Do the same as 6, but for subtraction, to pass test 3.
|
||||||
|
8. Modify the template so it also supports adding a regular integer to a BoundedInt, to pass test 4. Note that you can use `isinstance()` to determine the class of a variable.
|
||||||
|
9. Same as 8, but for subtraction.
|
||||||
|
|||||||
Reference in New Issue
Block a user