class Rectangle(): def __init__(self,w,h): self.width = w self.height = h def fitsInside(self,other): if self.width <= other.width and self.height <= other.height: return True elif self.width <= other.height and self.height <= other.width: return True else: return False with open("rectangles.txt") as f: N = int(f.readline()) txt = f.readline().split() prev = Rectangle(int(txt[0]),int(txt[1])) nests = True N -= 1 while N > 0 and nests: txt = f.readline().split() next = Rectangle(int(txt[0]),int(txt[1])) nests = prev.fitsInside(next) prev = next N -= 1 if nests: print("The file contains a nesting sequence.") else: print("The file does not contain a nesting sequence.")