# File: peri2.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 2022 # 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) # # construct the prompts # def prompt(xory, which): s = "Please enter the " + xory + " coordinate of the " + which + " point: " return s # # read in the co-ordinates # #iax = float(input("Please enter the x coordinate of the first point: ")) iax = float(input(prompt("x", "first"))) #iay = float(input("Please enter the y coordinate of the first point: ")) iay = float(input(prompt("y", "first"))) #ibx = float(input("Please enter the x coordinate of the second point: ")) ibx = float(input(prompt("x", "second"))) #iby = float(input("Please enter the y coordinate of the second point: ")) iby = float(input(prompt("y", "second"))) #icx = float(input("Please enter the x coordinate of the third point: ")) icx = float(input(prompt("x", "third"))) #icy = float(input("Please enter the y coordinate of the third point: ")) icy = float(input(prompt("y", "third"))) # # compute 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 # # print the corresponding triangle's perimeter # print("The perimeter is", temp)