Lesson 9: Walk the distanceTo
Challenge focus: 41 - 45
Coding Concepts: Returning value from functions and methods
Coding Adventure Part I
Key stage II
Class IV
Lesson Overview
Challenge Range | Coding Concepts | Sub Concepts | Resources |
41 - 45 | Variables |
| Lesson Plan 30 |
Coding Adventure Part I
Key stage II
Class IV
Lesson Objectives
Coding Adventure Part I
Key stage II
Class IV
Returned values from a function
Coding Adventure Part I
Key stage II
Class IV
Passing down values using variable
Working of the code:
1 | d = turtle.distanceTo bush |
2 | turtle.step d |
Coding Adventure Part I
Key stage II
Class IV
Passing down values without using variable
turtle.step turtle.distanceTo bush
Working of the code:
Step 1: turtle.distanceTo bush This code will execute and return distance of turtle from the bush.
Step 2: The returned distance from the turtle.distanceTo bush supplied to turtle.step
Coding Adventure Part I
Key stage II
Class IV
Demo 1
Using challenge 41, demonstrate the use of returned values to solve the problem in 5 lines.
Coding Adventure Part I
Key stage II
Class IV
Demo 1 Solution:
Coding Adventure Part I
Key stage II
Class IV
Activity 1: Debugging
Complete the code for challenge 42 so that monkey can reach banana on the other side of the river
Coding Adventure Part I
Key stage II
Class IV
Activity 1 Solution
i) Breaking down code
Step 1: distanceTo function returns the distance from the monkey to the banana.
Step 2: This returned value is given to step function
ii) Algorithm to solve the problem
Step 1: Start
Step 2: Turn monkey to banana
Step 3: Calculate the distance between banana and monkey
Step 3: Walk monkey to banana
Step 4: Stop
Coding Adventure Part I
Key stage II
Class IV
Activity 1 Solution
iii)
Coding Adventure Part I
Key stage II
Class IV
Activity 2
Coding Adventure Part I
Key stage II
Class IV
Activity 2 Solution
43
Coding Adventure Part I
Key stage II
Class IV
Activity 2 Solution
44
Coding Adventure Part I
Key stage II
Class IV
Activity 2 Solution
45
Coding Adventure Part I
Key stage II
Class IV
Key Points
Coding Adventure Part I
Key stage II
Class IV