class Box: # constructor method, assumes: # (x1, y1) is lower left coord # (x2, y2) is upper right coord def __init__(self, x1, y1, x2, y2): self.x1 = x1 self.y1 = y1 self.x2 = x2 self.y2 = y2 # width method def width(self): return (self.x2 - self.x1) # TODO height method # TODO area method # TODO isEnclosing method def isEnclosing(self, x, y): return True # TODO isOverlapping method def isOverlapping(self, b): return True # Test code b1 = Box(0, 0, 2, 2) b2 = Box(0, 0, 1, 3) print "b1.width()=%d" % b1.width() print "b1.isEnclosing(1, 1)=%s" % b1.isEnclosing(1, 1) print "b1.isOverlapping(b2)=%s" % b1.isOverlapping(b2)
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question