diff --git a/projects/013-compute-the-perimeter-of-a-polygon/python/main.py b/projects/013-compute-the-perimeter-of-a-polygon/python/main.py index e69de29..fc917b6 100644 --- a/projects/013-compute-the-perimeter-of-a-polygon/python/main.py +++ b/projects/013-compute-the-perimeter-of-a-polygon/python/main.py @@ -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}") + + + + + + + + + + + + + + +