def on_segment(p, q, r):
    """
    Given three colinear points p, q, r,
    the function checks if point q lies on line segment pr

    p: coordinate
    q: coordinate
    r: coordinate

    """

    if (q.x <= max(p.x, r.x) and q.x >= min(p.x, r.x) and
            q.y <= max(p.y, r.y) and q.y >= min(p.y, r.y)):
        return True
    else:
        return False