To extend algorithmic thinking to tasks to work out appropriate solutions
To explore the use of selection in a loop
To further explore the use of lists with indexing and iteration
Read over the pupil worksheet
This lesson builds on the previous lessons and allows your pupils to further investigate the use of selection, loops, arrays (lists in Python) as well as iterating over lists and using selection in a loop.
Ask pupils to read the introduction on their worksheet. We have provided them with starter code so they are all ready to move on to the next tasks. Ensure that they read the code carefully, using the comments to help them to fully understand it.
The running code will move their avatar towards the nearest artefacts and pick them up.
In this task, the code is examined further and pupils are are to extend it to show the description of the first thing in their backpack. They should be familiar with lists already but you might like to point out that the backpack is a list so they can look at individual elements using indexes in square brackets.
In the second task, pupils are asked to write a while loop to discover and output descriptions of each element in their backpack.
Pupils need to be able to use len() and list indexing.
Here is the suggested solution. Note that Kurono supports Python's formatted string literals (also called f-strings for short). A second example solution has been provided in case your class is not familiar with these.
Solution using f-strings
Solution without f-strings
Extension: can pupils change the output message so it outputs "a" or "some" depending on the item?
Here is one solution:
In this task, pupils need to count their artefacts by type. They need to create a variable for each artefact type, e.g. phone_count and add 1 to this value each time they find a match within a loop.
If they are unsure how to proceed, ask them where in their code they know the type of a single artefact. Answer: in the loop, here
Discuss the concept of running totals and perhaps try this as an exercise with any who are struggling to understand the concept:
I am going to say numbers to you and when I have finished, I want you to tell me their total. You cannot write them down or use a calculator. I might give you a lot of numbers so you won't be able to remember them all when I have finished. How are you going to add them up?
If they do not come up with a running total solution, then actually do this. Give them fairly simple numbers to add together but give them too many for them to be able to remember them all. Then ask them what they did.
What they did was this: every time you gave them a number, they added it to a total in their heads. The next question is: what was the total before I started giving you numbers? Answer: 0
Then they need to add code to count up phones and keyboards.
Here is one solution:
Extension: Some pupils might like to use lists for this task. They could create a 1D list of artefact type strings, e.g. TYPES = ["phone", "keyboard", "coins"]
and then have a separate counting list, e.g. counts = [0,0,0]
They could use a 2D list instead, if they prefer.
In this task, pupils are asked to make sure they have exactly five mobile phones and five keyboards. The backpack only holds ten things so they will need to drop any coins they are holding.
They can use a new function, find to get the index value of the first item of a specific type in their backpack. E.g.
Then they can return a DropAction with this index value so that Kurono removes this item from their backpack.
It is important to note that this function returns -1 if they are not holding an item of this type. They must only return a DropAction if the index is NOT -1. Otherwise, the last item in their backpack will be dropped and they might have wanted that!
Scaffold: first get pupils to drop coins. Then ask them to extend their code so that it drops mobile phones or keyboards if they have more than five of them.
Here is one solution.
Step 1: Drop coins
Step 2: Drop phones or keyboards if you have more than five of them
These tasks have allowed pupils to further explore the use of lists, iteration and selection in a loop, as well as interacting with the Kurono API.
Timing | Pupils' prior experience |
---|---|
One lesson of approximately 50 mins
Pupils should be familiar with Python programming, including the use of:
Variables
Assignment
Selection
Functions and procedures (subroutines)
Parameters
Loops
Lists