Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions projects/013-compute-the-perimeter-of-a-polygon/python/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
from math import sqrt

x_coordinate=input("Enter the first x-coordinate: ")
y_coordinate=input("Enter the first y-coordinate: ")
perimeter=0

next_x_coordinate=input("Enter the next x-coordinate (blank to quit): ")
while next_x_coordinate != "":
next_y_coordinate=input("Enter the next y-coordinate: ")

distance = sqrt((float(x_coordinate)-float(next_x_coordinate))**2+(float(y_coordinate)-float(next_y_coordinate))**2)
perimeter += distance

x_coordinate = next_x_coordinate
y_coordinate = next_y_coordinate

next_x_coordinate=input("Enter the next x-coordinate (blank to quit): ")

print(f"Perimeter: {perimeter:.2f}")