Python. Robot. Variables


Consider an example in which the robot needs to paint several rows of cells. Moreover, the number of cells in each row is different. 

In this case, we can do the following:
1) paint over all the cells in the row;
2) go back;
3) go to the next row;
4) repeat point 1.

These steps must be repeated as many times as we have rows.
You can notice that each time the number of cells that need to be painted increases by 1. This means that it is necessary to somehow count the number of cells that were painted over in the previous row. 

We will use variables
 
A variable is a value that has a name, a type, and a value. The value of a variable can change during program execution.
In computers, each variable is stored in its own memory location.

To create a variable, simply give it a name (use English) and store some value in it - for example, the number of cells to be painted in the first row. 

For example, you can create a variable n and store the value equal to 1 in it like this:
 
n = 1

Further, when writing a repeat loop, you can use this variable instead of a number:
 
repeat n:
    commands

After processing a row and moving on to the next row, you need to increase the value by 1. You can do this like this:
 
n = n + 1   

or shorter
 
n += 1
 
Program
n = 1 # create variable n and store value 1 in it repeat 6:     repeat n: # the number of cells in the row changes         right         paint over     repeat n: # you need to go back as much as you went to the right         to the left     down # move to a new row     n = n + 1 # the number of cells to be filled in the next row is 1 more