Exercise 2.1 solution not working

After copying the code for the solution to 2.1 and running the code, I receive this message in the terminal:

Traceback (most recent call last):
File “push_y.py”, line 6, in
n = int(sys.argv[1])
IndexError: list index out of range

Also, at the top of my code, it says “set as interpreter”, when I click on it, I receive the following message in the bottom right corner of the IDE. See below.

Any help on these? If someone could also explain why we use the line n = int(sys.agrv[1]), that would be helpful as its not explained in the tutorial or previous python for robotics course.


Hello @definis23 ,

I suppose you are trying to run the code with the following command:

python push_y.py

This is not correct, as you should specify in the command an integer to set the number of iterations the box will move on the Y axis. It should be something like this:

python push_y.py 5 (by changing the integer provided, the box will move more or less times)

And this is exactly what this line is doing:

n = int(sys.argv[1])

It captures the number provided in the command and uses it to move the box n iterations.