-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquestion2.py
More file actions
60 lines (33 loc) · 1.04 KB
/
question2.py
File metadata and controls
60 lines (33 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
from math import *
from graphics import *
def square(x):
return x**2
def dist(p1,p2):
d = sqrt(square(p2.getX()-p1.getX()) + square(p2.getY()-p1.getY()))
return d
def main():
win = GraphWin("Draw a triangle")
win.setCoords(0.0,0.0,10.0,10.0)
message = Text(Point(5,.5),"Click on three points")
message.draw(win)
# clickin in three points
p1 = win.getMouse()
p1.draw(win)
p2= win.getMouse()
p2.draw(win)
p3= win.getMouse()
p3.draw(win)
# drawing a triangle
triangle = Polygon(p1,p2,p3)
triangle.setFill('red')
triangle.draw(win)
# Find the perimeter and replace the Text by the perimeter
perimeter = dist(p1,p2)+dist(p1,p3) + dist(p2,p3)
message.setText("The perimeter is: {0:0.2f}".format(perimeter))
# calculate the Area
s = (perimeter) / 2
area = (s*(s-dist(p1,p2))*(s-dist(p1,p3))*(s-dist(p2,p3))) ** 0.5
message.setText("The Area is: {0:0.2f}".format(area))
win.getMouse()
win.close
main()