After reading some documentation on sys, I now know it gives back a list, in the case for the TSP problem what's the list of?

Hi Jose,

sys.argv is a list of the command-line arguments used when running the program. The first argument is always the name of the program.

The tsp.py example is meant to be run from the command line with the syntax

python tsp.py N

where N is an integer representing the number of random cities to use when solving the TSP. The second argument is used to construct a list of random points:

n = int(sys.argv[1])random.seed(1)points = [(random.randint(0, 100), random.randint(0, 100)) for i in range(n)]

If you want to fix the number of cities within the code rather than specifying it via command-line argument, you can replace the lines

if len(sys.argv) < 2:    print('Usage: tsp.py npoints')    sys.exit(1)n = int(sys.argv[1])

with (e.g.):

n = 25

Thanks!

Eli

Thank you so much for your answer, it clarifies a lot. No wonder when I tried to run it from Jupyter Notebook it showed an error message