PP Lab Programs
PP Lab Programs
# simple_geometry module
def area_rectangle(length,width):
return length*width
def area_circle(radius):
return 3.14*radius*radius
import simple_geometry
rect_len=4
rect_wid=6
area_rec=simple_geometry.area_rectangle(rect_len,rect_wid)
print(f"rectangle area:{area_rec}")
circ_rad=3
area_circ=simple_geometry.area_circle(circ_rad)
print(f"circle area:{area_circ}")
Output:
rectangle area:24
circle area:28.259999999999998
try:
result = a / b
print(f"Result: {result}")
except ZeroDivisionError:
except TypeError:
except Exception as e:
finally:
print("Operation complete.")
safe_divide(10,2)
safe_divide(10,0)
safe_divide(10,'a')
Output:
Result: 5.0
Operation complete.
Operation complete.
Operation complete.
a.
program:
fig, ax = plt.subplots()
ax.add_patch(rectangle)
plt.gca().set_aspect('equal', adjustable='box')
plt.show()
# Example usage
draw_rectangle(2, 3, 5, 8)
Output:
b.
program:
fig, ax = plt.subplots()
ax.add_patch(rectangle)
# Set the limits of the plot
ax.set_xlim(0, 1)
ax.set_ylim(0, 1)
plt.show()
Output:
c.
program:
class Point:
self.x = x
self.y = y
plt.figure(figsize=(3, 2))
plt.xlabel("X-axis")
plt.ylabel("Y-axis")
plt.title("Point Visualization")
plt.grid(True)
if __name__ == '__main__':
point1 = Point(5, 5)
point2 = Point(10, 7)
output:
d.
program:
class Circle:
self.x = x
self.y = y
self.r = r
self.color = color
ax.add_patch(patch)
if __name__ == '__main__':
c1 = Circle(5, 5, 2, 'red')
c2 = Circle(10, 7, 3, 'green')
ax.set_aspect('equal')
ax.set_xlim(0, 15)
ax.set_ylim(0, 15)
draw_circle(c1, ax)
draw_circle(c2, ax)
plt.grid(True)
plt.show()
output: