interpreter pattern def calculate_cost(self)return sum( cost for in self itemsdef calculate_discount(self)return sum( for in self discountsclass item(object)def __init__(selfnameitem_typecost)self name name self item_type item_type self cost cost class itemtype(object)def __init__(selfname)self name name class customer(object)def __init__(selfcustomer_typename)self customer_type customer_type self name name def is_a(selfcustomer_type)return self customer_type =customer_type class discount(object)def __init__(selfamount)self amount amount class customertype(object)def __init__(selfcustomer_type)self customer_type customer_type class rule(object)def __init__(selftab)self tab tab self conditions [self discounts [def add_condition(selftest_value)self conditions append(test_value