Write a python class Const, Square, Print so that I can write, for example, Cost(5) >> Square() >> Inc() >> Print() and the resulting python program will print 26 to the screen.
Write a python class Const, Square, Print so that I can write, for example, Cost(5) >> Square() >> Inc() >> Print() and the resulting python program will print 26 to the screen.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | class Const: def __init__(self, value): self.value = value def __rshift__(self, other): return other.__lshift__(self.value) class Square: def __lshift__(self, other): return Const(other ** 2) class Inc: def __lshift__(self, other): return Const(other + 1) class Print: def __lshift__(self, other): print(other.value) Const(5) >> Square() >> Inc() >> Print() |
I extracted the following code from that output:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | class Const: def __init__(self, value): self.value = value def __rshift__(self, other): return other.__lshift__(self.value) class Square: def __lshift__(self, other): return Const(other ** 2) class Inc: def __lshift__(self, other): return Const(other + 1) class Print: def __lshift__(self, other): print(other.value) Const(5) >> Square() >> Inc() >> Print() |
Running the following program:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | class Const: def __init__(self, value): self.value = value def __rshift__(self, other): return other.__lshift__(self.value) class Square: def __lshift__(self, other): return Const(other ** 2) class Inc: def __lshift__(self, other): return Const(other + 1) class Print: def __lshift__(self, other): print(other.value) Const(5) >> Square() >> Inc() >> Print() |
Traceback (most recent call last):
File "/usr/src/app/main.py", line 21, in <module>
Const(5) >> Square() >> Inc() >> Print()
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^~~~~~~~~
File "/usr/src/app/main.py", line 7, in __rshift__
return other.__lshift__(self.value)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/app/main.py", line 19, in __lshift__
print(other.value)
^^^^^^^^^^^
AttributeError: 'int' object has no attribute 'value'
Testing if the previous output contains the string All tests passed
: False
Write a python class Const, Square, Print so that I can write, for example, Cost(5) >> Square() >> Inc() >> Print() and the resulting python program will print 26 to the screen.
Write a python class Const, Square, Print so that I can write, for example, Cost(5) >> Square() >> Inc() >> Print() and the resulting python program will print 26 to the screen.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | class Const: def __init__(self, val): self.val = val class Square: def __init__(self, prev): self.prev = prev def __call__(self): return Square(self.prev.val * self.prev.val) class Inc: def __init__(self, prev): self.prev = prev def __call__(self): return Inc(self.prev.val + 1) class Print: def __init__(self, prev): self.prev = prev def __call__(self): print(self.prev.val) Const(5) >> Square() >> Inc() >> Print() |
I extracted the following code from that output:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | class Const: def __init__(self, val): self.val = val class Square: def __init__(self, prev): self.prev = prev def __call__(self): return Square(self.prev.val * self.prev.val) class Inc: def __init__(self, prev): self.prev = prev def __call__(self): return Inc(self.prev.val + 1) class Print: def __init__(self, prev): self.prev = prev def __call__(self): print(self.prev.val) Const(5) >> Square() >> Inc() >> Print() |
Running the following program:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | class Const: def __init__(self, val): self.val = val class Square: def __init__(self, prev): self.prev = prev def __call__(self): return Square(self.prev.val * self.prev.val) class Inc: def __init__(self, prev): self.prev = prev def __call__(self): return Inc(self.prev.val + 1) class Print: def __init__(self, prev): self.prev = prev def __call__(self): print(self.prev.val) Const(5) >> Square() >> Inc() >> Print() |
Traceback (most recent call last):
File "/usr/src/app/main.py", line 27, in <module>
Const(5) >> Square() >> Inc() >> Print()
^^^^^^^^
TypeError: Square.__init__() missing 1 required positional argument: 'prev'
Testing if the previous output contains the string All tests passed
: False
Write a python class Const, Square, Print so that I can write, for example, Cost(5) >> Square() >> Inc() >> Print() and the resulting python program will print 26 to the screen.
Write a python class Const, Square, Print so that I can write, for example, Cost(5) >> Square() >> Inc() >> Print() and the resulting python program will print 26 to the screen.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | class Const: def __init__(self, n): self.n = n class Square: def __init__(self, c): self.c = c class Inc: def __init__(self, s): self.s = s class Print: def __init__(self, i): print(i.s.c.n * i.s.c.n) Const(5) >> Square() >> Inc() >> Print() |
I extracted the following code from that output:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | class Const: def __init__(self, n): self.n = n class Square: def __init__(self, c): self.c = c class Inc: def __init__(self, s): self.s = s class Print: def __init__(self, i): print(i.s.c.n * i.s.c.n) Const(5) >> Square() >> Inc() >> Print() |
Running the following program:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | class Const: def __init__(self, n): self.n = n class Square: def __init__(self, c): self.c = c class Inc: def __init__(self, s): self.s = s class Print: def __init__(self, i): print(i.s.c.n * i.s.c.n) Const(5) >> Square() >> Inc() >> Print() |
Traceback (most recent call last):
File "/usr/src/app/main.py", line 18, in <module>
Const(5) >> Square() >> Inc() >> Print()
^^^^^^^^
TypeError: Square.__init__() missing 1 required positional argument: 'c'
Testing if the previous output contains the string All tests passed
: False
Write a python class Const, Square, Print so that I can write, for example, Cost(5) >> Square() >> Inc() >> Print() and the resulting python program will print 26 to the screen.
Write a python class Const, Square, Print so that I can write, for example, Cost(5) >> Square() >> Inc() >> Print() and the resulting python program will print 26 to the screen.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | class Const: def __init__(self, value): self.value = value class Square: def __init__(self, value): self.value = value ** 2 class Inc: def __init__(self, value): self.value = value + 1 class Print: def __init__(self, value): print(value) Const(5) >> Square() >> Inc() >> Print() |
I extracted the following code from that output:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | class Const: def __init__(self, value): self.value = value class Square: def __init__(self, value): self.value = value ** 2 class Inc: def __init__(self, value): self.value = value + 1 class Print: def __init__(self, value): print(value) Const(5) >> Square() >> Inc() >> Print() |
Running the following program:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | class Const: def __init__(self, value): self.value = value class Square: def __init__(self, value): self.value = value ** 2 class Inc: def __init__(self, value): self.value = value + 1 class Print: def __init__(self, value): print(value) Const(5) >> Square() >> Inc() >> Print() |
Traceback (most recent call last):
File "/usr/src/app/main.py", line 18, in <module>
Const(5) >> Square() >> Inc() >> Print()
^^^^^^^^
TypeError: Square.__init__() missing 1 required positional argument: 'value'
Testing if the previous output contains the string All tests passed
: False
Write a python class Const, Square, Print so that I can write, for example, Cost(5) >> Square() >> Inc() >> Print() and the resulting python program will print 26 to the screen.
Write a python class Const, Square, Print so that I can write, for example, Cost(5) >> Square() >> Inc() >> Print() and the resulting python program will print 26 to the screen.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | class Const: def __init__(self, n): self.n = n def __rshift__(self, other): return other(self.n) class Square: def __call__(self, n): return n * n class Inc: def __call__(self, n): return n + 1 class Print: def __call__(self, n): print(n) Const(5) >> Square() >> Inc() >> Print() |
I extracted the following code from that output:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | class Const: def __init__(self, n): self.n = n def __rshift__(self, other): return other(self.n) class Square: def __call__(self, n): return n * n class Inc: def __call__(self, n): return n + 1 class Print: def __call__(self, n): print(n) Const(5) >> Square() >> Inc() >> Print() |
Running the following program:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | class Const: def __init__(self, n): self.n = n def __rshift__(self, other): return other(self.n) class Square: def __call__(self, n): return n * n class Inc: def __call__(self, n): return n + 1 class Print: def __call__(self, n): print(n) Const(5) >> Square() >> Inc() >> Print() |
Traceback (most recent call last):
File "/usr/src/app/main.py", line 20, in <module>
Const(5) >> Square() >> Inc() >> Print()
~~~~~~~~~~~~~~~~~~~~~^^~~~~~~
TypeError: unsupported operand type(s) for >>: 'int' and 'Inc'
Testing if the previous output contains the string All tests passed
: False