11# area of trianlgle whose three coordinates are given by user
2+ import matplotlib .pyplot as plt
23x1 = float (input ("Enter x-coordinate of first point: " ))
34y1 = float (input ("Enter y-coordinate of first point: " ))
45x2 = float (input ("Enter x-coordinate of second point: " ))
@@ -12,7 +13,7 @@ def area_of_triangle(x1, y1, x2, y2, x3, y3):
1213area = area_of_triangle (x1 , y1 , x2 , y2 , x3 , y3 )
1314print (f"The area of the triangle formed by the points ({ x1 } , { y1 } ), ({ x2 } , { y2 } ), and ({ x3 } , { y3 } ) is: { area } square units." )
1415# plotting the triangle
15- import matplotlib . pyplot as plt
16+
1617plt .plot ([x1 , x2 , x3 , x1 ], [y1 , y2 , y3 , y1 ], 'b-' )
1718plt .scatter ([x1 , x2 , x3 ], [y1 , y2 , y3 ], color = 'red' )
1819plt .title ("Triangle formed by the given points" )
@@ -25,4 +26,4 @@ def area_of_triangle(x1, y1, x2, y2, x3, y3):
2526 file .write (f"The area of the triangle formed by the points ({ x1 } , { y1 } ), ({ x2 } , { y2 } ), and ({ x3 } , { y3 } ) is: { area } square units.\n " )
2627 file .write ("The triangle has been plotted and displayed.\n " )
2728#saving the figure
28- plt .savefig ('triangle_plot.png' )
29+ plt .savefig ('triangle_plot.png' )
0 commit comments