Answered step by step
Verified Expert Solution
Question
1 Approved Answer
PYTHON: Exercise .1 Write a Polygon class that is a sequence of 2D points represented by named tuples, so that each point is given a
PYTHON:
Exercise .1 Write a Polygon class that is a sequence of 2D points represented by named tuples, so that each point is given a name e.g., point 'A' is (4, 5). Thus: Point- pamedtuple(Point, [name', x', y]) The class defines the following a. constructors, setter and getter functions 1. A constructor that takes 3 or more points as arguments e.g., Polygon (A',5,0). (B',10,5). (C,5,10), (D'.-2,8) ), and initializes the polygon accordingly 2. A setter function that appends to the polygon a new point from given name and x, y coordinates. It should throw a user defined exception ExistingPointEtror if the point exists. Check the name of the point as well as x and y coordinates 3. A getter function that allows retrieving a point given its name. The function should throw a user defined exception PointNotEoundError if such point does not exist. 4. A getter function that takes index as an argument and returns the point at the given index. Throw IndexQutofBound exception. b. Update, delete and calculate functions 1. A function that allows updating the x and y coordinates of an existing point specified by its name. Throws 2. A function that deletes a point by name. Throws PointNotFoundErro, 3. A function that calculates and returns the perimeter of the polygon c. Length, print and comparison functions 1. A function that returns the number of points in the polygon, so that len(poly) works 2. A function that implements comparison operator. .g. polygon!--polygon2 3. A function that allows using print(poly) to print a polygon's points, in the following format: A: (5,6) - B: (6,7) -> C: (12,15) d. A function that draws a polygon on the screen, using Turtle graphics. Below is an example that draws a single line; adapt as necessary. For more info about Turtle graphics, see s://docs 3library/turtle html import turtle def drav. line(p1, p2, speed 2, color-blue) turtle speed(speed) turtlecolox(color) tutlewrite(A) drawalinel (0,50), (300,150)) Exercise .1 Write a Polygon class that is a sequence of 2D points represented by named tuples, so that each point is given a name e.g., point 'A' is (4, 5). Thus: Point- pamedtuple(Point, [name', x', y]) The class defines the following a. constructors, setter and getter functions 1. A constructor that takes 3 or more points as arguments e.g., Polygon (A',5,0). (B',10,5). (C,5,10), (D'.-2,8) ), and initializes the polygon accordingly 2. A setter function that appends to the polygon a new point from given name and x, y coordinates. It should throw a user defined exception ExistingPointEtror if the point exists. Check the name of the point as well as x and y coordinates 3. A getter function that allows retrieving a point given its name. The function should throw a user defined exception PointNotEoundError if such point does not exist. 4. A getter function that takes index as an argument and returns the point at the given index. Throw IndexQutofBound exception. b. Update, delete and calculate functions 1. A function that allows updating the x and y coordinates of an existing point specified by its name. Throws 2. A function that deletes a point by name. Throws PointNotFoundErro, 3. A function that calculates and returns the perimeter of the polygon c. Length, print and comparison functions 1. A function that returns the number of points in the polygon, so that len(poly) works 2. A function that implements comparison operator. .g. polygon!--polygon2 3. A function that allows using print(poly) to print a polygon's points, in the following format: A: (5,6) - B: (6,7) -> C: (12,15) d. A function that draws a polygon on the screen, using Turtle graphics. Below is an example that draws a single line; adapt as necessary. For more info about Turtle graphics, see s://docs 3library/turtle html import turtle def drav. line(p1, p2, speed 2, color-blue) turtle speed(speed) turtlecolox(color) tutlewrite(A) drawalinel (0,50), (300,150))
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started