py_area
Thu Apr 24 2025 20:56:17 GMT+0000 (Coordinated Universal Time)
Saved by
@tino
import numpy as np
class Pin:
def __init__(self, id, n_ring, radius):
self.id = id
self.n_ring = n_ring
self.radius = np.array(radius)
def calc_total_area(self):
return np.sum(np.pi * self.radius ** 2)
def calc_total_volume(self):
return np.sum((4 / 3) * np.pi * self.radius ** 3)
def print(self):
print(f"Pin ID: {self.id}, Rings: {self.n_ring}")
print(f"Total Area: {self.calc_total_area()}")
print(f"Total Volume: {self.calc_total_volume()}")
if __name__ == "__main__":
rad = [1.0, 2.0]
p = Pin(1, 2, rad)
p.print()
content_copyCOPY
Comments