Update page 'Day 3 homework'

j
2023-04-02 08:43:22 +02:00
parent febd26fe56
commit 17a6d3d375
+2 -10
@@ -22,19 +22,11 @@ class BoundedInt():
self.max = max self.max = max
``` ```
1. Read this: 1. Read this: https://docs.python.org/3/reference/datamodel.html?highlight=__int__#object.__int__
https://docs.python.org/3/reference/datamodel.html?highlight=__int__#object.__int__
Modify the template to pass test 1, which checks that `int()` called on your class will return the value of `i`. Modify the template to pass test 1, which checks that `int()` called on your class will return the value of `i`.
2. Read this, and the paragraph below it: https://docs.python.org/3/reference/datamodel.html?highlight=__int__#object.__add__ 2. Read this, and the paragraph below it: https://docs.python.org/3/reference/datamodel.html?highlight=__int__#object.__add__
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. 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.
Modify the template to pass test 2, which checks that: 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.
3. Do the same as 2, but for subtraction.
3. Do the same as 2, but