I’m trying to write out the coordinates of a 3d object, but I’m not sure how to list it.
so far I have:
class threed:
def __init__(self,length,width,height):
self.h =height
self.l = length
self.w = width
self.f=0
self.lwh = (length,width,height)
for i in range(1,3):
for j in range(1,3):
for k in range(1,3):
coordinates=threed(i,j,k)
The problem is my function rewrites the variable coordinates each time so that I can’t ever access coordinate (1,1,1) for example.
Note the above is for a 2x2x2 object.
How do I write it efficiently so that I can reference any coordinate as I need?
You can do:
to have each object. You may also use 3
forloops as well:Adding the
__repr__method to your class, you can see more easily the result.So the output of the first code will be:
To allow
threedobjects to be compared, you can add a__eq__method: