24 lines
761 B
Python
24 lines
761 B
Python
# Q10
|
|
|
|
# Imports
|
|
import math
|
|
|
|
# Get values from user
|
|
x1 = float(input("Enter x-coordinate for point 1: "))
|
|
y1 = float(input("Enter y-coordinate for point 1: "))
|
|
x2 = float(input("Enter x-coordinate for point 2: "))
|
|
y2 = float(input("Enter y-coordinate for point 2: "))
|
|
x3 = float(input("Enter x-coordinate for point 3: "))
|
|
y3 = float(input("Enter y-coordinate for point 3: "))
|
|
|
|
# Calculate the length of each side of the triangle
|
|
side1 = math.sqrt((x2 - x1)**2 + (y2 - y1)**2)
|
|
side2 = math.sqrt((x3 - x2)**2 + (y3 - y2)**2)
|
|
side3 = math.sqrt((x1 - x3)**2 + (y1 - y3)**2)
|
|
|
|
|
|
# Calculate the perimeter of the triangle
|
|
perimeter = side1 + side2 + side3
|
|
|
|
# Print the perimeter
|
|
print(f"The perimeter of the triangle is: {perimeter:.2f} units.") |