|

楼主 |
发表于 2020-6-3 21:40:51
|
显示全部楼层
本帖最后由 eobeom 于 2020-6-3 22:07 编辑
- class Rectangle:
- def __init__(self,width=0,length=0):
- self.__width=width
- self.__length=length
-
- def setWidth(self,width):
- self.__width=width
- def setLength(self,length):
- self.__height=height
- def getcalcArea(self):
- return self.__width*self.__length
- def __str__(self):
- return '(%d,%d)'%(self.__width,self.__length)
- class Indicating:
- def __init__(self,x,y):
- self.__x=x
- self.__y=y
-
- def setX(self,x):
- self.__x=x
- def setY(self,y):
- self.__y=y
- def __str__(self):
- return'(%d,%d)'%(self.__x,self.__y)
- rectangle=Rectangle(100,100)
- indicating=Indicating(0,0)
- print('位置是:',indicating,'大小为;',rectangle)
- print('矩形的面积是:',rectangle.getcalcArea())
- rectangle=Rectangle(200,200)
- indicating=Indicating(10,10)
- print('位置是:',indicating,'大小为;',rectangle)
- print('矩形的面积是:',rectangle.getcalcArea())
复制代码
请大佬帮我看看这样写对吗 |
|