Strings, lists and records · GCSE · OCR J277 2.2.3, AQA 8525 3.2.6, Edexcel 1CP2 6.3.1 · about 15 min
Making, indexing and changing a list; append, remove, in, split and join.
[1 mark]What does this program print?
legs = [20, 15, 30] print(legs[0], legs[-1], len(legs))
[1 mark]What does this program print?
notes = [262, 294, 330] notes[0] = 523 notes.append(349) print(notes)
[1 mark]legs = [20, 15, 30]. What happens with print(legs[3])?
[1 mark]Why use an array rather than separate variables such as reading1, reading2, reading3?
[1 mark]What does this program print?
sides = "30,20".split(",")
print(sides)
print(int(sides[0]) + int(sides[1]))[1 mark]What does this program print?
colours = ["red", "green"]
print("green" in colours, colours.index("green"))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.
30,20,30,20 and drive them.notes[10] = 440? And with notes.append(440) ten times?