design, write and debug programs that accomplish specific goals, including controlling or simulating physical systems; solve problems by decomposing them into smaller parts.
3.5a
LO: To call functions from another function (nested functions) (2).
We are trying to reduce the amount of typing we are doing and in the process becoming better programmers.
Let's look at the flow chart again so we can turn it into a function:

Let's use what we know about writing good functions to turn this into code.
#Year group or class #name #date #hurdles 2 #remember we need to know how to turn right def turn_right(): turn_left() turn_left() turn_left() write a function to jump def jump(): turn_left() move() turn_right() move() turn_right() move() turn_left()
Now let's look at how our code for Hurdles 1 looks now:
#Year group or class #name #date #hurdles 1 #plotting out the route we can see that we will need to turn right at the top of the jump def turn_right(): turn_left() turn_left() turn_left() write a function to jump def jump(): turn_left() move() turn_right() move() turn_right() move() turn_left() #write a function to complete the world def hurdles(): move() jump() move() jump() move() jump() move() #delete the indent to complete the function and then call it using its name hurdles()
Problems will change. One very important lesson to learn here is that the more repetitive code you have that is turned into functions - the easier it is to adapt to new problems and challenges.
Try saving your code to Hurdles 2 and trying to adapt it to Hurdles 1 - imagine doing it without functions!
Hurdles 3 is also available to challenge children.