So I am trying to write a piece of code so it takes a list of points rather than a single point and returns boolean True only if all points in the list are in the rectangle.
For example,
allIn((0,0), (5,5), [(1,1), (0,0), (5,5)]) should return True but allIn((0,0), (5,5), [(1,1), (0,0), (5,6)]) should return False empty list of points allIn((0,0), (5,5), []) should return False I can't seem to get the return to match the above example for both false returns.The empty list should return false. Any idea where I am going wrong?
def allIn(firstCorner=(0,0), secondCorner=(0,0), pointList=[]): x1 = firstCorner[0] y1 = firstCorner[1] x2 = secondCorner[0] y2 = secondCorner[1] for i in range(len(pointList)): p_x = pointList[i][0] p_y = pointList[i][1] if not ((p_x >= x1 and p_x < x2) and (p_y >= y1 and p_y < y2)): return False return True print(allIn((0,0), (5,5), [(1,1), (0,0), (5,5)])) print(allIn((0,0), (5,5), [(1,1), (0,0), (5,6)])) print(allIn((0,0), (5,5), []))