Year 7 · Summer 1
Scratch II: Subroutines and lists · Lesson 2 of 5
Lists: high scores and inventories
PracticalTopic 14 Programming further
Year 7 · Scratch II: Subroutines and lists · Lesson 2 of 5
You will learn to
- Explain what a list is and why it is better than lots of separate variables.
- Use blocks to add an item, delete an item and show one item from a list.
- Explain that Scratch counts list items from 1, but Python counts from 0.
Year 7 · Scratch II: Subroutines and lists · Lesson 2 of 5
Success criteria
You have got it when you can say:
- I can make a list of names and a list of scores.
- I can add an item, delete an item and show item 1.
- I can say that the first item is item 1 in Scratch and index 0 in Python.
Year 7 · Scratch II: Subroutines and lists · Lesson 2 of 5
Retrieval starter
Questions from before. Write your answers, then show them.
- Last lesson
The Tube map leaves out real distances. That's…
A AbstractionB Pattern recognitionC Decomposition
A. Abstraction
- Last unit
An 'if… else…' is…
A IterationB SequenceC Selection
C. Selection
- Earlier this year
Which turns www.bbc.co.uk into an IP address?
A DNSB SMTPC HTTP
A. DNS
Year 7 · Scratch II: Subroutines and lists · Lesson 2 of 5
Key words (1 of 2)
- list
- One name holding many values in order. Also called an array.
- index
- An item's position in a list, counting from 0.
- Subroutine
- A named block of code you can call when needed.
- Function
- A subroutine that returns a value.
Year 7 · Scratch II: Subroutines and lists · Lesson 2 of 5
Key words (2 of 2)
- Parameter
- A placeholder in a subroutine for a value passed in.
- Validation
- Checking input is reasonable before using it.
- Boundary data
- Test data at the very edge of what's allowed.
The explanation · step 1 of 1 · part 1 of 2
Lists
A list (or array) stores many values under one name, in order.
scores = [12, 45, 33, 50]
| Index | 0 | 1 | 2 | 3 |
|---|---|---|---|---|
| Value | 12 | 45 | 33 | 50 |
Why start at 0? The index means 'how many steps from the start'. The first item is 0 steps away.
The explanation · step 1 of 1 · part 2 of 2
Lists (continued)
scores[0]→ 12scores[-1]→ 50 (the last one)scores.append(28)adds to the endlen(scores)→ how many itemsscores[10]→ error: no item there
Year 7 · Scratch II: Subroutines and lists · Lesson 2 of 5
Quick quiz · 1 of 3
Which loop always runs at least once?
- A FOR i ← 1 TO 0
- B WHILE … ENDWHILE
- C REPEAT … UNTIL
C. REPEAT … UNTIL
REPEAT … UNTIL checks its condition at the end, after the first run.
Year 7 · Scratch II: Subroutines and lists · Lesson 2 of 5
Quick quiz · 2 of 3
x ← 4, then x ← x × 2, then x ← x + 1. What is x?
- A 12
- B 8
- C 9
C. 9
4 × 2 = 8, then 8 + 1 = 9. Each line replaces the old value.
Year 7 · Scratch II: Subroutines and lists · Lesson 2 of 5
Quick quiz · 3 of 3
Which shape is used for OUTPUT total?
- A Parallelogram
- B Diamond
- C Rectangle
A. Parallelogram
Input and output are always parallelograms.
Year 7 · Scratch II: Subroutines and lists · Lesson 2 of 5
Exit ticket
Answer on paper before you go. Then check.
In ["a", "b", "c"], the index of "c" is…
A 2B cC 3
A. 2 Counting starts at 0: a = 0, b = 1, c = 2.
word = "Python". What is word[1:4]?
A "ytho"B "yth"C "Pyth"
B. "yth" Start at index 1 (y), stop before index 4 (o): y, t, h. That's 4 − 1 = 3 characters.