Skip to content

Instantly share code, notes, and snippets.

@JohnReeves
Created May 2, 2014 13:13
Show Gist options
  • Save JohnReeves/cb73f1c0f8c996800e01 to your computer and use it in GitHub Desktop.
Save JohnReeves/cb73f1c0f8c996800e01 to your computer and use it in GitHub Desktop.
```python
class Shape:
def __init__(self, dim1, dim2):
self.dim1=dim1
self.dim1=dim2
def area(self):
return self.dim1*self.dim2
def perimeter(self):
return 2*(self.dim1+self.dim2)
class Rectangle(Shape):
def __init__(self, length, breadth):
self.dim1=length
self.dim2=breadth
class Square(Rectangle):
def __init__(self,length):
self.dim1=length
self.dim2=length
class Triangle(Shape):
def __init__(self, base, height):
self.dim1=base
self.dim2=height
def area(self):
return 0.5 * (self.dim1*self.dim2)
rectangle=Rectangle(3,4)
print(rectangle.area())
square=Square(3)
print(square.area())
triangle=Triangle(3,4)
print(triangle.area())
square=Square(5)
print(square.area())
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment