The answersDownload the PDF
Worksheet

F3.3 Lists: one-dimensional arrays

Strings, lists and records · GCSE · OCR J277 2.2.3, AQA 8525 3.2.6, Edexcel 1CP2 6.3.1 · about 15 min

BugBotLab
NameClassDate

What this lesson is about

Making, indexing and changing a list; append, remove, in, split and join.

Questions 6 marks in all

  1. [1 mark]What does this program print?

    legs = [20, 15, 30]
    print(legs[0], legs[-1], len(legs))
  2. [1 mark]What does this program print?

    notes = [262, 294, 330]
    notes[0] = 523
    notes.append(349)
    print(notes)
  3. [1 mark]legs = [20, 15, 30]. What happens with print(legs[3])?

    1. AIndexError: there is no index 3
    2. BIt prints 30
    3. CIt prints 0
    4. DIt prints None
  4. [1 mark]Why use an array rather than separate variables such as reading1, reading2, reading3?

    1. AOne name holds them all, and a loop can process every item
    2. BArrays use less electricity
    3. CSeparate variables cannot hold numbers
    4. DArrays are always sorted
  5. [1 mark]What does this program print?

    sides = "30,20".split(",")
    print(sides)
    print(int(sides[0]) + int(sides[1]))
  6. [1 mark]What does this program print?

    colours = ["red", "green"]
    print("green" in colours, colours.index("green"))

The task: a changing tune

Start with notes = [262, 294, 330]. Change the first note to 523, add 349 to the end, print how many notes there are as 4 notes, then play every note in the list for 0.3 seconds. Change the list with list operations, not by typing a new list.

# the two lines every program starts with: the commands, then the robot
from bugbot import *
connect()

notes = [262, 294, 330]

Plan your program here, then type it in and press Run.

QR code
Do it on the robot
www.bugbotlab.com/learn/f3-3-lists-one-dimensional-arrays/
The simulator checks it and tells you when it passes. Nothing to install, no account.

Challenges

  1. Make a list of four colours and show each on the LED with a loop over the indexes.
  2. Ask for side lengths as 30,20,30,20 and drive them.
  3. What happens with notes[10] = 440? And with notes.append(440) ten times?