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 | class Const: def __init__(self, value): self.value = value def __rshift__(self, other): return other(self.value) class Square: def __call__(self, value): return value * value class Inc: def __call__(self, value): return value + 1 class Print: def __call__(self, value): print(value) # Example usage 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 | class Const: def __init__(self, value): self.value = value def __rshift__(self, other): return other(self.value) class Square: def __call__(self, value): return value * value class Inc: def __call__(self, value): return value + 1 class Print: def __call__(self, value): print(value) # Example usage 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 | class Const: def __init__(self, value): self.value = value def __rshift__(self, other): return other(self.value) class Square: def __call__(self, value): return value * value class Inc: def __call__(self, value): return value + 1 class Print: def __call__(self, value): print(value) # Example usage 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 22, in <module>
Const(5) >> Square() >> Inc() >> Inc() >> Print()
TypeError: unsupported operand type(s) for >>: 'int' and 'Inc'
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 | class Const: def __init__(self, value): self.value = value def __rshift__(self, other): return other(self.value) class Square: def __call__(self, value): return value * value class Inc: def __call__(self, value): return value + 1 class Print: def __call__(self, value): print(value) # Example usage 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 | class Const: def __init__(self, value): self.value = value def __rshift__(self, other): return other(self.value) class Square: def __call__(self, value): return value * value class Inc: def __call__(self, value): return value + 1 class Print: def __call__(self, value): print(value) # Example usage 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 | class Const: def __init__(self, value): self.value = value def __rshift__(self, other): return other(self.value) class Square: def __call__(self, value): return value * value class Inc: def __call__(self, value): return value + 1 class Print: def __call__(self, value): print(value) # Example usage 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 22, in <module>
Const(5) >> Square() >> Inc() >> Inc() >> Print()
TypeError: unsupported operand type(s) for >>: 'int' and 'Inc'
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 | class Const: def __init__(self, value): self.value = value def __rshift__(self, other): return other(self.value) class Square: def __call__(self, value): return value * value class Inc: def __call__(self, value): return value + 1 class Print: def __call__(self, value): print(value) # Example usage 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 | class Const: def __init__(self, value): self.value = value def __rshift__(self, other): return other(self.value) class Square: def __call__(self, value): return value * value class Inc: def __call__(self, value): return value + 1 class Print: def __call__(self, value): print(value) # Example usage 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 | class Const: def __init__(self, value): self.value = value def __rshift__(self, other): return other(self.value) class Square: def __call__(self, value): return value * value class Inc: def __call__(self, value): return value + 1 class Print: def __call__(self, value): print(value) # Example usage 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 22, in <module>
Const(5) >> Square() >> Inc() >> Inc() >> Print()
TypeError: unsupported operand type(s) for >>: 'int' and 'Inc'
Testing if the previous output contains the string 625
: False