-
-
Save Vasanth375/53b1749a76dd87bc3cb3a1f922175bd3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Shape: | |
def area(self): | |
pass | |
class Rectangle(Shape): | |
def __init__(self, width, height): | |
self.width = width | |
self.height = height | |
def area(self): | |
return self.width * self.height | |
class Circle(Shape): | |
def __init__(self, radius): | |
self.radius = radius | |
def area(self): | |
return 3.14 * self.radius ** 2 | |
shapes = [Rectangle(10, 20), Circle(5)] | |
for shape in shapes: | |
print(shape.area()) | |
#Output: 200, 78.5 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment