In [9]:
#init
#calculate area
#print
class Rectangle(object):
def __init__ (self, w=0, h=0):
self.w=w
self.h=h
def get_area(self):
return self.w*self.h
def __str__(self):
return("width:{}, height:{}, area:{}".format(self.w, self.h, self.get_area() ))
In [10]:
rec=Rectangle(w=3,h=4)
In [11]:
print(rec)
In [12]:
class Square(Rectangle):
def __init__(self, edge):
self.w=edge
self.h=edge
In [13]:
sq=Square(5)
In [14]:
print(sq)
In [22]:
%matplotlib inline
import numpy as np
from matplotlib import pyplot as plt
In [23]:
x=np.arange(-1.0*np.pi, np.pi, 0.1)
In [24]:
y=np.sin(x)
In [26]:
plt.plot(x,y,'r--o')
Out[26]:
In [30]:
from myshape.rect import Rectangle as Rect
In [31]:
rect=Rect(5,7)
In [32]:
print(rect)
In [ ]: