Add the unary Not expression.
With And, Or and Not you now have a complete boolean algebra over the context.
class Var:
def __init__(self, name):
self.name = name
def interpret(self, context):
return bool(context.get(self.name, False))
class Const:
def __init__(self, value):
self.value = value
def interpret(self, context):
return self.value
class And:
def __init__(self, a, b):
self.a = a
self.b = b
def interpret(self, context):
return self.a.interpret(context) and self.b.interpret(context)
class Or:
def __init__(self, a, b):
self.a = a
self.b = b
def interpret(self, context):
return self.a.interpret(context) or self.b.interpret(context)
class Not:
def __init__(self, expr):
self.expr = expr
def interpret(self, context):
"""Return the logical negation of the child result."""
# TODO: return not self.expr.interpret(context)
pass
The editor and the test runner need a wide screen. Open this page on a desktop browser and your progress will be waiting.
Add the unary Not expression.
With And, Or and Not you now have a complete boolean algebra over the context.
Press Run Tests or ββ© to check your solution.