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 28 29 | class Const(object): def __init__(self, value): self.value = value def __rshift__(self, other): return other.execute(self.value) class Square(object): def execute(self, value): self.value = value * value return self def __rshift__(self, other): return other.execute(self.value) class Inc(object): def execute(self, value): self.value = value + 1 return self def __rshift__(self, other): return other.execute(self.value) class Print(object): def execute(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 22 23 24 25 26 27 28 29 | class Const(object): def __init__(self, value): self.value = value def __rshift__(self, other): return other.execute(self.value) class Square(object): def execute(self, value): self.value = value * value return self def __rshift__(self, other): return other.execute(self.value) class Inc(object): def execute(self, value): self.value = value + 1 return self def __rshift__(self, other): return other.execute(self.value) class Print(object): def execute(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 31 32 33 34 35 36 37 38 | class Const(object): def __init__(self, value): self.value = value def __rshift__(self, other): return other.execute(self.value) class Square(object): def execute(self, value): self.value = value * value return self def __rshift__(self, other): return other.execute(self.value) class Inc(object): def execute(self, value): self.value = value + 1 return self def __rshift__(self, other): return other.execute(self.value) class Print(object): def execute(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') |
27
625
Traceback (most recent call last):
File "/usr/src/app/main.py", line 38, 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 26 27 28 29 30 31 32 33 34 35 36 | class Const(object): def __init__(self, value): self.value = value def __rshift__(self, other): return other(self.value) class Square(object): def __init__(self, value=None): if value is not None: self.value = value * value else: self.value = None def __rshift__(self, other): return other(self.value) class Inc(object): def __init__(self, value=None): if value is not None: self.value = value + 1 else: self.value = None def __rshift__(self, other): return other(self.value) class Print(object): def __init__(self, value=None): if value is not None: print(value) else: print(self.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 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | class Const(object): def __init__(self, value): self.value = value def __rshift__(self, other): return other(self.value) class Square(object): def __init__(self, value=None): if value is not None: self.value = value * value else: self.value = None def __rshift__(self, other): return other(self.value) class Inc(object): def __init__(self, value=None): if value is not None: self.value = value + 1 else: self.value = None def __rshift__(self, other): return other(self.value) class Print(object): def __init__(self, value=None): if value is not None: print(value) else: print(self.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 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | class Const(object): def __init__(self, value): self.value = value def __rshift__(self, other): return other(self.value) class Square(object): def __init__(self, value=None): if value is not None: self.value = value * value else: self.value = None def __rshift__(self, other): return other(self.value) class Inc(object): def __init__(self, value=None): if value is not None: self.value = value + 1 else: self.value = None def __rshift__(self, other): return other(self.value) class Print(object): def __init__(self, value=None): if value is not None: print(value) else: print(self.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 37, in <module>
Const(5) >> Square() >> Inc() >> Inc() >> Print()
File "/usr/src/app/main.py", line 7, in __rshift__
return other(self.value)
TypeError: 'Square' object is not callable
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 28 29 30 31 32 33 34 35 36 | class Const(object): def __init__(self, value): self.value = value def __rshift__(self, other): return other(self.value) class Square(object): def __init__(self, value=None): if value is not None: self.value = value * value else: self.value = None def __rshift__(self, other): return other(self.value) class Inc(object): def __init__(self, value=None): if value is not None: self.value = value + 1 else: self.value = None def __rshift__(self, other): return other(self.value) class Print(object): def __init__(self, value=None): if value is not None: print(value) else: print("No value to print.") # 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 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | class Const(object): def __init__(self, value): self.value = value def __rshift__(self, other): return other(self.value) class Square(object): def __init__(self, value=None): if value is not None: self.value = value * value else: self.value = None def __rshift__(self, other): return other(self.value) class Inc(object): def __init__(self, value=None): if value is not None: self.value = value + 1 else: self.value = None def __rshift__(self, other): return other(self.value) class Print(object): def __init__(self, value=None): if value is not None: print(value) else: print("No value to print.") # 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 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | class Const(object): def __init__(self, value): self.value = value def __rshift__(self, other): return other(self.value) class Square(object): def __init__(self, value=None): if value is not None: self.value = value * value else: self.value = None def __rshift__(self, other): return other(self.value) class Inc(object): def __init__(self, value=None): if value is not None: self.value = value + 1 else: self.value = None def __rshift__(self, other): return other(self.value) class Print(object): def __init__(self, value=None): if value is not None: print(value) else: print("No value to print.") # 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 37, in <module>
Const(5) >> Square() >> Inc() >> Inc() >> Print()
File "/usr/src/app/main.py", line 7, in __rshift__
return other(self.value)
TypeError: 'Square' object is not callable
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 28 29 30 31 32 33 34 35 36 | class Const(object): def __init__(self, value): self.value = value def __rshift__(self, other): return other(self.value) class Square(object): def __init__(self, value=None): if value is not None: self.value = value * value else: self.value = None def __rshift__(self, other): return other(self.value) class Inc(object): def __init__(self, value=None): if value is not None: self.value = value + 1 else: self.value = None def __rshift__(self, other): return other(self.value) class Print(object): def __init__(self, value=None): if value is not None: print(value) else: print("No value provided.") # 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 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | class Const(object): def __init__(self, value): self.value = value def __rshift__(self, other): return other(self.value) class Square(object): def __init__(self, value=None): if value is not None: self.value = value * value else: self.value = None def __rshift__(self, other): return other(self.value) class Inc(object): def __init__(self, value=None): if value is not None: self.value = value + 1 else: self.value = None def __rshift__(self, other): return other(self.value) class Print(object): def __init__(self, value=None): if value is not None: print(value) else: print("No value provided.") # 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 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | class Const(object): def __init__(self, value): self.value = value def __rshift__(self, other): return other(self.value) class Square(object): def __init__(self, value=None): if value is not None: self.value = value * value else: self.value = None def __rshift__(self, other): return other(self.value) class Inc(object): def __init__(self, value=None): if value is not None: self.value = value + 1 else: self.value = None def __rshift__(self, other): return other(self.value) class Print(object): def __init__(self, value=None): if value is not None: print(value) else: print("No value provided.") # 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 37, in <module>
Const(5) >> Square() >> Inc() >> Inc() >> Print()
File "/usr/src/app/main.py", line 7, in __rshift__
return other(self.value)
TypeError: 'Square' object is not callable
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 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): self.value = value * value return self def __rshift__(self, other): return other(self.value) class Inc: def __call__(self, value): self.value = value + 1 return self def __rshift__(self, other): return other(self.value) class Print: def __call__(self, value): print(value) return self # 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 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): self.value = value * value return self def __rshift__(self, other): return other(self.value) class Inc: def __call__(self, value): self.value = value + 1 return self def __rshift__(self, other): return other(self.value) class Print: def __call__(self, value): print(value) return self # 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 31 32 33 34 35 36 37 38 39 | class Const: def __init__(self, value): self.value = value def __rshift__(self, other): return other(self.value) class Square: def __call__(self, value): self.value = value * value return self def __rshift__(self, other): return other(self.value) class Inc: def __call__(self, value): self.value = value + 1 return self def __rshift__(self, other): return other(self.value) class Print: def __call__(self, value): print(value) return self # 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') |
27
625
Traceback (most recent call last):
File "/usr/src/app/main.py", line 39, in <module>
assert answer == expected, f'Wrong answer; got {answer} instead of {expected}'
AssertionError: Wrong answer; got <__main__.Print object at 0x7f70b7b53760> instead of 0
Testing if the previous output contains the string 625
: True