Question: in python Download the file hw7.py from Blackboard, and use it as a starting point for this assign- ment. Read the code for the supplied

in python
in python Download the file hw7.py from Blackboard, and use it as
a starting point for this assign- ment. Read the code for the
supplied methods set_vertices, num_vertices, get_string to see how this class represents a
Polygon in the plane. The idea is that a Polygon is rep-

Download the file hw7.py from Blackboard, and use it as a starting point for this assign- ment. Read the code for the supplied methods set_vertices, num_vertices, get_string to see how this class represents a Polygon in the plane. The idea is that a Polygon is rep- resented by an ordered list of n vertices (10.30), (71.4).....(n-1, Yn-1) in such a way that the edges of the polygon connect the vertices as follows: Edge 0: (:10.yo) to (x1.y), Edge 1: (2.9) to (2, y2), Edge n-2: (1.-2. Yn 2) to (n-1Yn-1), Edge n-1: (En-1-Yn-1) to (to, yo). For example, a Polygon with 5 vertices is illustrated below. (749) (30) (1) (10 points) Write the method perimeter which computes and returns the perim ter of a Polygon object from its verties. This method should not print anything. It must return the result. (2) (10 points) Write the member function area which computes and returns the area of a Polygon object from its vertices, using the formula below. This method should not print anything. It must return the result. You may assume that the only intersection between the edges occurs at the vertices of adjacent edges. In that case, the area is given by (rah - 1980) + (7112 - *) + + (*... -- 19->) + (xu-19-86). In case you're interested, this formula can be derived from Green's Theorem in Calculus. Many Culeulus textbooks include this either explicitly or is an exercise Polygon: init_self): Initializes Polygon object. self.x = 0) self.xil is the x-coordinate of vertex 'i'. selt.y = 11 self.yli) is the y-coordinate of vertex 'i'. ******* det set_vertices(self, coordinates): # Set the vertices for this polygon object. #coordinates' is a list of floats, interpretted as follows: #coordinateste is the x-coordinate of vertex 1 # coordinates[1] is the y-coordinate of vertex 1 #coordinates[2] is the x-coordinate of vertex 2, # coordinates[3] is the y-coordinate of vertex 2. # and so on. # The polygon has sides connecting: #vertex Band vertex 1 #vertex 1 and vertex 2, #vertex (n-2) and vertex (n-1) #vertex (n-1) and vertex e n len(coordinates) 1 2 : printeset_vertices(): Error! 'coordinates must "contain an even number of elements") return false self.x. (coordinates[21] for i in range(n//2) self. y coordinatest2+1for i in range//2)1 return True *********** der num vertices(sel): # Return the number of vertices in this Polygon object. Totum len(self.x) det get_stringselt): Return string representation of this Polygon object # It will be a list of of the vertices, in order n = self.num_vertices result" Start with anoty string and appendwach vertex to it. for 1 in range(n): result (o) (1)".Format self. 1. solr.yil) Icn 11 result cetur result www WWW de perimeterself) Return the perimeter of this polygon object. ######## ############# #################### def perimeter(self): # Return the perimeter of this Polygon object. # Probem 1. # Delete this pass' statement, and replace it # with your implementation. pass ############################################### def area (self): # Return the area of this Polygon object. # Problem 2. # Again, delete this pass statement, and replace it # with your implementation. pass # # # # # # # # # # # # ###################### # # # # ### # Do NOT change anything below here!!!!!!! # ######## ############ P = Polygon() # Create a Polygon object, P. # This next line sets p to be the polygon #whose vertices are (1,0), (2, -1),(3,0), (2,1). # You should be able to work out by hand what the perimeter # and area of this polygon are so I suggest using this as P.set_vertices([1,0, 2,-1, 3.0, 2.11) # Print out some information about the Polygon P. print(" has vertices P.get_string()) D = P.perimeter) print(its perimeter is (0) Formatip) - P.areal) print-Ito arou in conformat(all

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!