0% found this document useful (0 votes)
3 views2 pages

Midterm 0

The document outlines the requirements for a midterm exam in ITP107, focusing on a Python program that calculates the perimeter of polygons based on provided vertices. It specifies the input format, sample outputs, and essential functions needed, such as calculating distance, perimeter, and longest segment. The program must handle multiple points and print results with one decimal precision.

Uploaded by

kjh03010630
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views2 pages

Midterm 0

The document outlines the requirements for a midterm exam in ITP107, focusing on a Python program that calculates the perimeter of polygons based on provided vertices. It specifies the input format, sample outputs, and essential functions needed, such as calculating distance, perimeter, and longest segment. The program must handle multiple points and print results with one decimal precision.

Uploaded by

kjh03010630
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Midterm exam

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.

1.2 Sample input and expected output


1.2.1 Example 1
How many points to read? 3
x: 0
y: 0
x: 3
y: 0
x: 3
y: 4
Perimeter: 12.0
Longest segment length: 5.0

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

1.3 Function requirements


To get full marks:

ˆ 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

Comments are not required for this exam.

You might also like