def predict_class_with_tree(instance, tree):

    """Used the passed decision tree to predict the class of the passed instance"""

    # go down through the tree nodes evaluating each non-terminal node's condition based on the instance features
    node = tree
    while not node.is_terminal:
        if node.evaluate(instance[node.feature_name]):
            node = node.right_child
        else:
            node = node.left_child

    # the predicted class is the one given by the reached terminal node
    return node.class_value