The user needs to input a set of coordinates like so (0,0), (0,1), (1,1), (1,0)
The code I wrote for that looks like this:
def get_coords():
#user_input = raw_input("Enter a list of points. For example (0,0) (0,1) (1,1) (1,0)\n")
print "Enter a list of points. For example (0,0) (0,1) (1,1) (1,0)\n"
uin = sys.stdin.readline().strip()
try:
#coords = map(int, uin.split(' '))
coords = [tuple(map(int, point.replace('(', '').replace(')', '').split(','))) for point in uin.split(' ')]
return coords
except ValueError:
print "Please enter the coordinates in the format mentioned"
exit()
I'm sure there is a better, more elegant way to do this?