This is how you can create a list of random (x, y) points ...
import random as rn
# a list of 5 random (x, y) points
rp_list = []
for k in range(5):
rp_list.append((rn.randint(1, 21), rn.randint(1, 21)))
print "Random point list:"
print rp_list # eg. [(19, 12), (20, 13), (15, 2), (11, 19), (20, 14)] Now let the user input a number of (x, y) points ...
# user inputs 5 (x, y) points
up_list = []
for k in range(5):
x_prompt = "Enter x%d = " % (k+1)
y_prompt = "Enter y%d = " % (k+1)
x = int(raw_input(x_prompt))
y = int(raw_input(y_prompt))
up_list.append((x, y))
print "User point list:"
print up_list # eg. [(7, 21), (10, 18), (19, 12), (12, 18), (4, 9)] Last not least compare the two lists ...
# compare 2 lists
rp_list = [(19, 12), (20, 13), (15, 2), (11, 19), (20, 14)]
up_list = [(7, 21), (10, 18), (19, 12), (12, 18), (4, 9)]
for p in rp_list:
if p in up_list:
print p,"in both lists"
Try it, study it, experiment with it ...
vegaseat
DaniWeb's Hypocrite
Moderator
5,989 posts since Oct 2004
Reputation Points: 1,345
Solved Threads: 1,417