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.

  1. Last lesson

    The Tube map leaves out real distances. That's…

    A AbstractionB Pattern recognitionC Decomposition

    A. Abstraction

  2. Last unit

    An 'if… else…' is…

    A IterationB SequenceC Selection

    C. Selection

  3. 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]
Index0123
Value12453350
?Why?

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] → 12
  • scores[-1] → 50 (the last one)
  • scores.append(28) adds to the end
  • len(scores) → how many items
  • scores[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?

  1. A FOR i ← 1 TO 0
  2. B WHILE … ENDWHILE
  3. 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?

  1. A 12
  2. B 8
  3. 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?

  1. A Parallelogram
  2. B Diamond
  3. 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.

  1. 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.

  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.