-
Code class MyInt: def __init__(self, value): self.value = value def subtract(self, another_int): self.value = self.value - another_int.value def sub(a: int, b: int) -> int: int_a, int_b = MyInt(a), MyInt(b) int_a.subtract(int_b) return int_a.value
Test Cases import codewars_test as test import random # Random test cases .describe("Random tests") def random_tests(): .it("Random tests") def random_test_cases(): for _ in range(100): a = random.randint(-1000, 1000) b = random.randint(-1000, 1000) expected = a - b test.assert_equals(sub(a,b), expected)
Output:
-
Code from operator import sub- class MyInt:
- def __init__(self, value):
- self.value = value
- def subtract(self, another_int):
- self.value = self.value - another_int.value
- def sub(a: int, b: int) -> int:
- int_a, int_b = MyInt(a), MyInt(b)
- int_a.subtract(int_b)
- return int_a.value
- All
- {{group.name}} ({{group.count}})
This comment has been reported as {{ abuseKindText }}.
Show
This comment has been hidden. You can view it now .
This comment can not be viewed.
- |
- Reply
- Edit
- View Solution
- Expand 1 Reply Expand {{ comments?.length }} replies
- Collapse
- Remove
- Remove comment & replies
- Report
{{ fetchSolutionsError }}