Created
April 21, 2018 16:45
-
-
Save Aeres-u99/83c7e7042e3f36b3e77173e91df70ffa 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
import math | |
class Shape(object): | |
def __init__(self,base,side): | |
self.base=base | |
self.side=side | |
def area(self): | |
return self.base*self.side | |
def perimeter(self): | |
return 2*(self.base+self.side) | |
def __str__(self): | |
return 'I am a %s with area of %d' % (type(self).__name__, self.area()) | |
class Rectangle(Shape): | |
def __init__(self, base, side): | |
super(Rectangle, self).__init__(base,side) | |
class Square(Shape): | |
def __init__(self, base): | |
super(Square, self).__init__(base,base) | |
d1=Rectangle(4,5) | |
d2=Square(4) | |
print(d1.area()) | |
print(d2.area()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment