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()
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter