Let's say that I want to create a class circle that, provided a value r and a value delta_r, can calculate the annulus area of a couple of circles. Afterwards, using this class, I want to create a list with several couples of circles.
How can I add a condition, built in the class, that allows to append values only if r < 7? So that, in the example, the list C is still created but includes only results till r=6.
import numpy as np
from numpy import pi
class circle:
def __init__(self, r=1, delta_r=0.1):
self.r = r
self.delta_r = delta_r
self.area1 = pi*r**2
self.area2 = pi*(r+delta_r)**2
self.annulus = self.area2 - self.area1
C_range = np.arange(1, 10)
C = []
for n in C_range:
C.append(circle(n, 0.2))
Aucun commentaire:
Enregistrer un commentaire