Skip to content

Commit 40a9a6e

Browse files
committed
2 parents 2adb7f9 + 97020cc commit 40a9a6e

2 files changed

Lines changed: 7 additions & 5 deletions

File tree

area_of_triangle.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# area of trianlgle whose three coordinates are given by user
2+
import matplotlib.pyplot as plt
23
x1 = float(input("Enter x-coordinate of first point: "))
34
y1 = float(input("Enter y-coordinate of first point: "))
45
x2 = float(input("Enter x-coordinate of second point: "))
@@ -12,7 +13,7 @@ def area_of_triangle(x1, y1, x2, y2, x3, y3):
1213
area = area_of_triangle(x1, y1, x2, y2, x3, y3)
1314
print(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+
1617
plt.plot([x1, x2, x3, x1], [y1, y2, y3, y1], 'b-')
1718
plt.scatter([x1, x2, x3], [y1, y2, y3], color='red')
1819
plt.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')

limits.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
#finding limits of a function using user defined function
2+
import numpy as np
3+
import matplotlib.pyplot as plt
24
def find_limit(func, x, approach):
35
if approach == 'left':
46
return func(x - 0.0001) # Approaching from the left
@@ -30,8 +32,7 @@ def function(x):
3032

3133

3234
#plot function to visualize limits
33-
import numpy as np
34-
import matplotlib.pyplot as plt
35+
3536
x_vals = np.linspace(0.5, 1.5, 100)
3637
y_vals = [function(x) for x in x_vals]
3738
plt.plot(x_vals, y_vals, label='f(x)')
@@ -41,4 +42,4 @@ def function(x):
4142
plt.title('Function Visualization')
4243
plt.legend()
4344
plt.grid(True)
44-
plt.show()
45+
plt.show()

0 commit comments

Comments
 (0)