For this code what I'm trying to accomplish is this: There are two lists x_list and y_list, and I'm checking to see if there are any coordinate pairs already there. The first index of x_list and y_list is the first coordinate, the second index of both of them is the second coordinate, etc.

In the coordinates function I want to look at both of the lists, and test to see if that coordinate is already present, and if not it appends it to the 2 lists, creating another coordinate pair.

The error that I'm getting is when it's tested, it says both "Already a room there" and appends the coordinates to the list, even though they're already there.

Example:

coordindates(0,1)

coordindates(0,2)

is supposed to return "Already a room there" for the first call, and appends 0 to X_list and 2 to y_list for the second.

网友答案:

You're code can't work, since you do the check-and-add for every couple. So if you have N coordinates, you'll add the new coordinate N times, or N-1 if it's already present. You have to do something like this: