Midterm 0
Midterm 0
ITP107
April 26, 2021
1 Polygon perimeter
1.1 Description
Write a Python program to read in a file which contains a number of vertices (버텍스) for polygons
(다각형), calculate the perimeter (둘레) of each polygon, and determine which has the largest perimeter.
Also, print out the longest segment length (i.e., the longest length between two adjacent points).
All numbers should be printed out with 1 digit after the decimal point.
You program will first read in one integer, indicating how many points there will be. Then, in a loop,
you will read in x and y coordinates (floats) for each point. Then, you will perform the perimeter and
longest segment calculations and produce output.
This represents the triangle from (0, 0) → (3, 0) → (3, 4) → (0, 0). Notice that the perimeter must
include the distance from the last point back to the first point.
1.2.2 Example 2
How many points to read? 4
x: 1
y: 1
x: 2
y: 2
x: 3
y: 1
x: 2
y: 0
Perimeter: 5.7
Longest segment length: 1.4
1
1.2.3 Example 3
How many points to read? 10
x: 5.5
y: 3
x: 5.7
y: 4
x: 5.9
y: 5
x: 6.1
y: 4
x: 6.3
y: 3
x: 6.5
y: 0
x: 7
y: 5
x: 10
y: 0
x: 100
y: -50.5
x: 1000
y: 0
Perimeter: 2017.1
Longest segment length: 994.5
You must build a list of points. You can represent a point as a tuple of 2 floats.
You must have a function distance, which returns the distance between two points
You must have a function perimeter, which returns the perimeter of a list of points
You must have a function longest segment, which returns the length of the longest segment in a
list of points