interpreter pattern class condition(object)def __init__(selfcondition_function)self test condition_function def evaluate(selftab)return self test(tabclass discounts(object)def __init__(self)self children [def calculate(selftab)return sum( calculate(tabfor in self childrendef add(selfchild)self children append(childdef remove(selfchild)self children remove(childclass discount(object)def __init__(selftest_functiondiscount_function)self test test_function self discount discount_function def calculate(selftab)return sum(self discount(itemfor item in tab items if self test(item)class rule(object)def __init__(selftab)self tab tab self conditions andconditions(self discounts discounts(def add_conditions(selfconditions)self conditions add(conditionsdef add_discount(selftest_functiondiscount_function)discount discount(test_functiondiscount_functionself discounts add(discount