# File: peri4.py # Compute the perimeter of a triangle; user enters the points defining it # WARNING: input is not error checked (see peri-c.py for how to do it right) # # Matt Bishop, MHI 289I, Fall 2024 # import math # load up the math functions # # compute the distance between two points (x1, y1) and (x2, y2) # def dist(x1, y1, x2, y2): temp = (x1 - x2) ** 2 + (y1 - y2) ** 2 return math.sqrt(temp) # # compute the perimeter of the triangle defined by (x1, y1), (x2, y2), (x3, y3) # def compperi(x1, y1, x2, y2, x3, y3): d1 = dist(x1, y1, x2, y2) d2 = dist(x1, y1, x3, y3) d3 = dist(x2, y2, x3, y3) return d1 + d2 + d3 # # construct the prompts # def prompt(xory, which): s = "Please enter the " + xory + " coordinate of the " + which + " point: " return s # # get co-ordinates of points # def getcoord(axis, which): return float(input(prompt(axis, which))) # ################ MAIN PROGRAM # # # read in the co-ordinates # iax = getcoord("x", "first") iay = getcoord("y", "first") ibx = getcoord("x", "second") iby = getcoord("y", "second") icx = getcoord("x", "third") icy = getcoord("y", "third") # # print the corresponding triangle's perimeter # #d1 = dist(iax, iay, ibx, iby) #d2 = dist(iax, iay, icx, icy) #d3 = dist(ibx, iby, icx, icy) #temp = d1 + d2 + d3 temp = compperi(iax, iay, ibx, iby, icx, icy) print("The perimeter is", temp)