Skip to content

Commit 0091de4

Browse files
committed
学习demo
1 parent 72668e9 commit 0091de4

File tree

6 files changed

+874
-3
lines changed

6 files changed

+874
-3
lines changed

Diff for: .idea/aws.xml

+11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: .idea/misc.xml

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: .idea/python-demo1.iml

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: .idea/vcs.xml

-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: mypr16.py

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
class MyRectangle:
2+
'''
3+
这个类用于描述一个矩形
4+
'''
5+
# 构造方法
6+
def __init__(self,x=0,y=0,width=100,height=100):
7+
self.x = float(x)
8+
self.y = float(y)
9+
self.width = float(width)
10+
self.height = float(height)
11+
12+
13+
#计算矩形的面积
14+
def getArea(self):
15+
return self.width * self.height
16+
17+
#计算矩形的周长
18+
def getPerimeter(self):
19+
return 2*(self.width + self.height)
20+
21+
#海龟绘图
22+
def draw(self):
23+
import turtle
24+
p = turtle.Pen()
25+
p.penup()
26+
p.goto(self.x,self.y) #移动到指定位置
27+
p.pendown()
28+
p.goto(self.x + self.width,self.y)# x轴方向
29+
p.goto(self.x+self.width,self.y+self.height) # y轴方向
30+
p.goto(self.x,self.y+self.height)
31+
p.goto(self.x,self.y) # 回到原点
32+
turtle.done() #结束绘图
33+
34+
35+
p1 = MyRectangle(-2,3,9.8,10)
36+
print(p1.getArea(),"面积")
37+
print(p1.getPerimeter(),"周长")
38+
p1.draw()
39+

0 commit comments

Comments
 (0)