Variables

Variables#

In Python, it is possible to give a name to a value in order to reuse it

later. In the following cell, we give the name a to the value 3. We call

a a variable.

a = 3

Each time the variable a appears, it will be replaced by its value:

a
3
a + 1
4

The following cell randomly chooses two integers between 1 and 9 and names them respectively x and y. It then constructs a large empty maze with the exception of a door at the coordinates \((x,y)\):

from laby.global_fr import *
from random import randint
import labyrinthes

x = randint(1,9)
y = randint(1,9)

labyrinthes.une_porte(x, y, largeur=20)

You can now find the position of the door by consulting the respective values

of the x and y variables:

x
4
y
2

Use two for loops as well as the x and y coordinates of the door to guide

the ant to the exit:

debut()
### BEGIN SOLUTION
for i in range(x):
    avance();
gauche();
for i in range(y):
    avance();
### END SOLUTION
ouvre();
assert est_gagnant()