So, I have a Class 'Cube', which has 4 attributes, namely x_coordinate, y_coordinate, z_coordinate and access_point. I have instantiated 1000 objects for the class 'Cube' and have added them to a list named 'Cube_list'. For all the 1000 objects, the attributes 'x_coordinate', 'y_coordinate', 'z_coordinate' have integer values between 0 and 9, while the value for the attribute 'access_point' is set to zero. Next, I ask the user for the coordinates for three access points, 'fx', 'fy', 'fz' for the first access point, 'sx', 'sy', 'sz' for the second access point, and 'tx', 'ty', 'tz' for the third access point. Next, for the three class instances with those three coordinates, we change the attribute 'access_point' to '1', and then append those three instances to another list called 'Access_Point_List'.
My code is running fine except for the last part where I am unable to append those specific objects to the list 'Access_Point_List'.
Here's my complete code:
class Cube:
def __init__(self, x, y, z, block_access_point):
self.x_coordinate = x
self.y_coordinate = y
self.z_coordinate = z
self.access_point = block_access_point
def set_access_point(self, set_ap):
self.access_point = set_ap
Cube_list = []
Access_Point_List = []
for i in range(10):
for j in range(10):
for k in range(10):
Cube_ijk = Cube(i, j, k, 0)
Cube_list.append(Cube_ijk)
print("No of elements in cube_list are:", len(Cube_list))
fx, fy, fz = input("Enter coordinates of the first access point: ").split()
sx, sy, sz = input("Enter coordinates of the second access point: ").split()
tx, ty, tz = input("Enter coordinates of the third access point: ").split()
for i in Cube_list:
if ((i.x_coordinate == fx) and (i.y_coordinate == fy) and (i.z_coordinate == fz)) or ((i.x_coordinate == sx) and (i.y_coordinate == sy) and (i.z_coordinate == sz)) or ((i.x_coordinate == tx) and (i.y_coordinate == ty) and (i.z_coordinate == tz)):
i.set_access_point(1)
Access_Point_List.append(i)
print("No of elements in access_point_list are:", len(Access_Point_List))
for i in Access_Point_List:
print(i.x_coordinate, end=" ")
print(i.y_coordinate, end=" ")
print(i.z_coordinate)
I checked and confirmed that the 1000 class objects are added correctly to the list 'Cube_list'. I printed the values of 'fx', 'fy', 'fz', 'sx', 'sy', 'sz', 'tx', 'ty', 'tz' and they are accepted and displayed correctly. I verified that the 'i.set_access_point(1)' command is also working as I had expected. But the command 'Access_Point_List.append(i)' is not appending the specific three objects to the list 'Access_Point_List'. The command 'print("No of elements in access_point_list are:", len(Access_Point_List))' is printing zero. The last block of print statement is not showing anything. I tried using copy.copy by this command 'Access_Point_List.append(copy.copy(i))'. But it's not working.