my_van
.move_forwards
, turn_left
and turn_right
are, in fact, procedures. Once called, they cause the van to move. This is why when we want the van to move forwards, we call its move_forwards
procedure by putting () after its name (e.g. my_van.move_forwards()
)n
times, where n
is a whole number such as 3. It works with any name inserted where the word number is shown in the example. (The built-in range function just tells the loop how many times to repeat.)my_van.move_forwards()
3 times. You can use the count variable inside the body of the loop if you want the van’s behaviour to differ depending on how many times the for loop was executed. On the first time through the loop, its value will be 0, incremented by one each time around the loop.:
at the end of the for
line because this indicates that a sequence of instructions should follow (we call them the body of the loop). These instructions must all be indented by the same amount (ideally by 4 spaces).if
, elif
and else
statements must all be indented to the same level as each other, and all require a colon :
at the end of their statement.elif
is short for else if
if
, elif
or else
statement.True
or False
.while
not statement repeats until the condition is True
.while
condition is met (we call it the body of the loop).def
keyword. The procedure needs a meaningful name where procedurename
is placed in the example. You must have a pair of brackets () and a colon :
after it.