Starter You have been asked to write a program to store the names of everybody in a class. Assuming there are 20 pupils in the class, how would you do this?
Lists & Arrays Python
Objectives 2.3.2 Understand the need for and be able to select and use data structures one-dimensional arrays two-dimensional arrays
What are Arrays? If we think of variables as a box. Arrays are a collection of boxes. Array - list of homogeneous items Each “box” has an address starting at 0. We call the address it’s INDEX [0] ‘Alf’ [1] ‘Betsy’ [2] ‘Charlie’ [3] ‘David’
Printing Lists Individual elements may be printed by using the name of the list and then the index of the element you wish to print in square [] brackets. Think: What programming construct could you use to print out every element in a list?
Activity 1. Complete Activity 1 the VLE.
More than one dimension? We were working with 1 Dimensional Arrays. These are effectively lists. What about if we had lists….of lists??? [0] [1] [2] [3] [4] What Value is at Scores[1][2]? Jimmy 12 15 17 19 Joanna 9 16 18 20 Jess 5 6 7 John 4 [0] 16 [1] [2] [3]
Activity 1. Complete Activity 2 the VLE.
To store related information Week 2 - Recap What is the purpose of a list? How do you create a list? Add an element? Remove a element? To store related information scores = [35, 62, 98, 54, 21] scores.append(71) scores.pop(2) Teacher note: Random numbers
Plenary If variables are like boxes, what are lists? What methods can we use to add and remove elements to/from a list? What is a list element?