Skip to content

Instantly share code, notes, and snippets.

@steveh
Created July 23, 2019 23:37
Show Gist options
  • Save steveh/6552ffcf3eeb721d053ad106b8dad247 to your computer and use it in GitHub Desktop.
Save steveh/6552ffcf3eeb721d053ad106b8dad247 to your computer and use it in GitHub Desktop.
class Shape:
def area(self):
raise NotImplementedError
def perimeter(self):
raise NotImplementedError
class Rectangle(Shape):
def __init__(self, side1, side2):
self.side1 = side1
self.side2 = side2
def area(self):
return self.side1 * self.side2
def perimeter(self):
return (self.side1 * 2) + (self.side2 * 2)
class Triangle(Shape):
def __init__(self, side1, side2, side3):
pass
class Circle(Shape):
def __init__(self, radius):
pass
rectangle = Rectangle(10.0, 50.0)
triangle = Triangle(3.0, 7.0, 11.0)
circle = Circle(14)
print('Rectangle area: {}, perimeter: {}'.format(
rectangle.area(), rectangle.perimeter()))
print('Triangle area: {}, perimeter: {}'.format(
triangle.area(), triangle.perimeter()))
print('Circle area: {}, perimeter: {}'.format(
circle.area(), circle.perimeter()))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment