""" Exercise 6.9 from "A primer on...". Change an existing function for compuuting the area of a triangle, from taking a list to a dictionary as input parameter. """ #original function, using a list: def triangle_area(v): [x1,y1] = v[0] [x2,y2] = v[1] [x3,y3] = v[2] A = abs(0.5*( (x2*y3)-(x3*y2)-(x1*y3)+(x3*y1)+(x1*y2)-(x2*y1) )) return A #usage: v1 = (0,0); v2 = (1,0); v3 = (0,2) vertices = [v1, v2, v3] print(triangle_area(vertices)) #modified version, using a dict: def triangle_area_dict(v): [x1,y1] = v[1] [x2,y2] = v[2] [x3,y3] = v[3] A = abs(0.5*( (x2*y3)-(x3*y2)-(x1*y3)+(x3*y1)+(x1*y2)-(x2*y1) )) return A vertices = {1:v1, 2:v2, 3:v3} #same vertices, but with keys 1,2,3 print(triangle_area_dict(vertices)) """ Terminal> python area_triangle_dict.py 1.0 1.0 """