def combineRulesWithOperator(listOfRules, operator):
    """
    Takes a list of rules and makes an overall rule that ties them together
    with the AND or the OR operator

    Parameters
    ----------
    listOfRules: list
        A list of string representation of rules
    operator: str
        Should be either AND or OR

    Returns
    -------
    total: str
        String representation of the rules combined using the given operator
    """
    assert type(listOfRules) == list
    assert all(map(lambda r: type(r) == str, listOfRules))
    assert operator.lower() in ['and', 'or']

    if len(listOfRules) == 1:
        return listOfRules[0]

    operator = operator.lower()
    total = listOfRules[0]
    for i in range(1, len(listOfRules)):
        total = operator + "(" + total + ", " + listOfRules[i] + ")"
    return total