Write a python class Const, Square, Print so that I can write, for example, Cost(5) >> Square() >> Inc() >> Inc() >> Print() and the resulting python program will print 27 to the screen.
Write a python class Const, Square, Print so that I can write, for example, Cost(5) >> Square() >> Inc() >> Inc() >> Print() and the resulting python program will print 27 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, n): self.n = n def __rshift__(self, other): return other(self.n) class Square: def __call__(self, n): return Const(n*n) class Inc: def __call__(self, n): return Const(n+1) class Print: def __call__(self, n): print(n) Const(5) >> Square() >> Inc() >> 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, n): self.n = n def __rshift__(self, other): return other(self.n) class Square: def __call__(self, n): return Const(n*n) class Inc: def __call__(self, n): return Const(n+1) class Print: def __call__(self, n): print(n) Const(5) >> Square() >> Inc() >> 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 27 28 29 | class Const: def __init__(self, n): self.n = n def __rshift__(self, other): return other(self.n) class Square: def __call__(self, n): return Const(n*n) class Inc: def __call__(self, n): return Const(n+1) class Print: def __call__(self, n): print(n) Const(5) >> Square() >> Inc() >> Inc() >> Print() answer = Const(2) >> Square() >> Inc() >> Square() >> Square() >> Print() expected = 0 assert answer == expected, f'Wrong answer; got {answer} instead of {expected}' print('All tests passed') |
27
625
Traceback (most recent call last):
File "/usr/src/app/main.py", line 29, in <module>
assert answer == expected, f'Wrong answer; got {answer} instead of {expected}'
AssertionError: Wrong answer; got None instead of 0
Testing if the previous output contains the string 625
: True
Write a python class Const, Square, Print so that I can write, for example, Cost(5) >> Square() >> Inc() >> Inc() >> Print() and the resulting python program will print 27 to the screen.
Write a python class Const, Square, Print so that I can write, for example, Cost(5) >> Square() >> Inc() >> Inc() >> Print() and the resulting python program will print 27 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 | class Const: def __init__(self, n): self.n = n class Square: def __init__(self, obj): self.obj = obj def __rrshift__(self, other): return self.obj.n ** 2 class Inc: def __init__(self, obj): self.obj = obj def __rrshift__(self, other): self.obj.n += 1 return self.obj class Print: def __init__(self, obj): self.obj = obj def __rrshift__(self, other): print(self.obj.n) return self.obj c = Const(5) >> Square() >> Inc() >> 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 | class Const: def __init__(self, n): self.n = n class Square: def __init__(self, obj): self.obj = obj def __rrshift__(self, other): return self.obj.n ** 2 class Inc: def __init__(self, obj): self.obj = obj def __rrshift__(self, other): self.obj.n += 1 return self.obj class Print: def __init__(self, obj): self.obj = obj def __rrshift__(self, other): print(self.obj.n) return self.obj c = Const(5) >> Square() >> Inc() >> 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 27 28 29 30 31 32 33 34 | class Const: def __init__(self, n): self.n = n class Square: def __init__(self, obj): self.obj = obj def __rrshift__(self, other): return self.obj.n ** 2 class Inc: def __init__(self, obj): self.obj = obj def __rrshift__(self, other): self.obj.n += 1 return self.obj class Print: def __init__(self, obj): self.obj = obj def __rrshift__(self, other): print(self.obj.n) return self.obj c = Const(5) >> Square() >> Inc() >> Inc() >> Print() answer = Const(2) >> Square() >> Inc() >> Square() >> Square() >> Print() expected = 0 assert answer == expected, f'Wrong answer; got {answer} instead of {expected}' print('All tests passed') |
Traceback (most recent call last):
File "/usr/src/app/main.py", line 26, in <module>
c = Const(5) >> Square() >> Inc() >> Inc() >> Print()
TypeError: Square.__init__() missing 1 required positional argument: 'obj'
Testing if the previous output contains the string 625
: False
Write a python class Const, Square, Print so that I can write, for example, Cost(5) >> Square() >> Inc() >> Inc() >> Print() and the resulting python program will print 27 to the screen.
Write a python class Const, Square, Print so that I can write, for example, Cost(5) >> Square() >> Inc() >> Inc() >> Print() and the resulting python program will print 27 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, a): self.a = a def __rshift__(self, other): return other(self.a) class Square: def __call__(self, a): return Const(a*a) class Inc: def __call__(self, a): return Const(a+1) class Print: def __call__(self, a): print(a) Const(5) >> Square() >> Inc() >> 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, a): self.a = a def __rshift__(self, other): return other(self.a) class Square: def __call__(self, a): return Const(a*a) class Inc: def __call__(self, a): return Const(a+1) class Print: def __call__(self, a): print(a) Const(5) >> Square() >> Inc() >> 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 27 28 | class Const: def __init__(self, a): self.a = a def __rshift__(self, other): return other(self.a) class Square: def __call__(self, a): return Const(a*a) class Inc: def __call__(self, a): return Const(a+1) class Print: def __call__(self, a): print(a) Const(5) >> Square() >> Inc() >> Inc() >> Print() answer = Const(2) >> Square() >> Inc() >> Square() >> Square() >> Print() expected = 0 assert answer == expected, f'Wrong answer; got {answer} instead of {expected}' print('All tests passed') |
27
625
Traceback (most recent call last):
File "/usr/src/app/main.py", line 28, in <module>
assert answer == expected, f'Wrong answer; got {answer} instead of {expected}'
AssertionError: Wrong answer; got None instead of 0
Testing if the previous output contains the string 625
: True
Write a python class Const, Square, Print so that I can write, for example, Cost(5) >> Square() >> Inc() >> Inc() >> Print() and the resulting python program will print 27 to the screen.
Write a python class Const, Square, Print so that I can write, for example, Cost(5) >> Square() >> Inc() >> Inc() >> Print() and the resulting python program will print 27 to the screen.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | 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 ** 2 + 1) |
I extracted the following code from that output:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | 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 ** 2 + 1) |
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 | 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 ** 2 + 1) answer = Const(2) >> Square() >> Inc() >> Square() >> Square() >> Print() expected = 0 assert answer == expected, f'Wrong answer; got {answer} instead of {expected}' print('All tests passed') |
Traceback (most recent call last):
File "/usr/src/app/main.py", line 22, in <module>
answer = Const(2) >> Square() >> Inc() >> Square() >> Square() >> Print()
TypeError: Square.__init__() missing 1 required positional argument: 'c'
Testing if the previous output contains the string 625
: False
Write a python class Const, Square, Print so that I can write, for example, Cost(5) >> Square() >> Inc() >> Inc() >> Print() and the resulting python program will print 27 to the screen.
Write a python class Const, Square, Print so that I can write, for example, Cost(5) >> Square() >> Inc() >> Inc() >> Print() and the resulting python program will print 27 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 27 | class Const: def __init__(self, val): self.val = val class Square: def __init__(self, prev): self.prev = prev def __rrshift__(self, other): return Square(other.val * self.prev.val) class Inc: def __init__(self, prev): self.prev = prev def __rrshift__(self, other): return Inc(other.val + self.prev.val) class Print: def __init__(self, prev): self.prev = prev def __rrshift__(self, other): print(self.prev.val) return self.prev.val Const(5) >> Square() >> Inc() >> 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 27 | class Const: def __init__(self, val): self.val = val class Square: def __init__(self, prev): self.prev = prev def __rrshift__(self, other): return Square(other.val * self.prev.val) class Inc: def __init__(self, prev): self.prev = prev def __rrshift__(self, other): return Inc(other.val + self.prev.val) class Print: def __init__(self, prev): self.prev = prev def __rrshift__(self, other): print(self.prev.val) return self.prev.val Const(5) >> Square() >> Inc() >> 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 27 28 29 30 31 32 33 34 35 36 | class Const: def __init__(self, val): self.val = val class Square: def __init__(self, prev): self.prev = prev def __rrshift__(self, other): return Square(other.val * self.prev.val) class Inc: def __init__(self, prev): self.prev = prev def __rrshift__(self, other): return Inc(other.val + self.prev.val) class Print: def __init__(self, prev): self.prev = prev def __rrshift__(self, other): print(self.prev.val) return self.prev.val Const(5) >> Square() >> Inc() >> Inc() >> Print() answer = Const(2) >> Square() >> Inc() >> Square() >> Square() >> Print() expected = 0 assert answer == expected, f'Wrong answer; got {answer} instead of {expected}' print('All tests passed') |
Traceback (most recent call last):
File "/usr/src/app/main.py", line 28, in <module>
Const(5) >> Square() >> Inc() >> Inc() >> Print()
TypeError: Square.__init__() missing 1 required positional argument: 'prev'
Testing if the previous output contains the string 625
: False