# File: peri1.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 2019 # 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) # # read in the co-ordinates # iax = float(input("Please enter the x coordinate of the first point: ")) iay = float(input("Please enter the y coordinate of the first point: ")) ibx = float(input("Please enter the x coordinate of the second point: ")) iby = float(input("Please enter the y coordinate of the second point: ")) icx = float(input("Please enter the x coordinate of the third point: ")) icy = float(input("Please enter the y coordinate of the third point: ")) # # compute the corresponding triangle's perimeter # #d1 = math.sqrt((iax - ibx) ** 2 + (iay - iby) ** 2) d1 = dist(iax, iay, ibx, iby) #d2 = math.sqrt((iax - icx) ** 2 + (iay - icy) ** 2) d2 = dist(iax, iay, icx, icy) #d3 = math.sqrt((ibx - icx) ** 2 + (iby - icy) ** 2) d3 = dist(ibx, iby, icx, icy) temp = d1 + d2 + d3 # # print the corresponding triangle's perimeter # print("The perimeter is", temp)