Skip to content

Instantly share code, notes, and snippets.

@wo0dyn
Created November 3, 2021 00:18
Show Gist options
  • Save wo0dyn/92482da38e03f4e29bb335a280ab848a to your computer and use it in GitHub Desktop.
Save wo0dyn/92482da38e03f4e29bb335a280ab848a to your computer and use it in GitHub Desktop.

In Computer Programming; 1 + 1 = …

class A(int):
    def __add__(self, value):
        return int(str(self) + str(value))


class B(int):
    pass


class C(int):
    def __add__(self, value):
        return int(bin(int(str(self)) + int(str(value)))[2:])


class D(int):
    def __add__(self, value):
        return f"{self}{value}"


for answer in (A, B, C, D):
    x = y = answer(1)
    print(f"{answer.__name__}: {x} + {y} = {x + y!r}")
A: 1 + 1 = 11
B: 1 + 1 = 2
C: 1 + 1 = 10
D: 1 + 1 = '11'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment